Sha256: 97aca4efacbab99f51271ed3367c9d5f7f6635e880e4bbc0290ab4baf23eca8c

Contents?: true

Size: 1.27 KB

Versions: 49

Compression:

Stored size: 1.27 KB

Contents

#
# converted from the gitrb project
#
# authors:
#    Matthias Lederhofer <matled@gmx.net>
#    Simon 'corecode' Schubert <corecode@fs.ei.tum.de>
#    Scott Chacon <schacon@gmail.com>
#
# provides native ruby access to git objects and pack files
#

module Grit
  module GitRuby
    module Internal
      class FileWindow
        def initialize(file, version = 1)
          @file = file
          @offset = nil
          if version == 2
            @global_offset = 8
          else
            @global_offset = 0
          end
        end

        def unmap
          @file = nil
        end

        def [](*idx)
          idx = idx[0] if idx.length == 1
          case idx
          when Range
            offset = idx.first
            len = idx.last - idx.first + idx.exclude_end? ? 0 : 1
          when Fixnum
            offset = idx
            len = nil
          when Array
            offset, len = idx
          else
            raise RuntimeError, "invalid index param: #{idx.class}"
          end
          if @offset != offset
            @file.seek(offset + @global_offset)
          end
          @offset = offset + len ? len : 1
          if not len
            @file.read(1).getord(0)
          else
            @file.read(len)
          end
        end
      end
    end
  end
end

Version data entries

49 entries across 49 versions & 10 rubygems

Version Path
gitlab-grit-2.8.3 lib/grit/git-ruby/internal/file_window.rb
gitlab-grit-2.8.2 lib/grit/git-ruby/internal/file_window.rb
gitlab-grit-2.8.1 lib/grit/git-ruby/internal/file_window.rb
gitlab-grit-2.8.0 lib/grit/git-ruby/internal/file_window.rb
gitlab-grit-2.7.3 lib/grit/git-ruby/internal/file_window.rb
gitlab-grit-2.6.12 lib/grit/git-ruby/internal/file_window.rb
gitlab-grit-2.7.2 lib/grit/git-ruby/internal/file_window.rb
gitlab-grit-2.6.11 lib/grit/git-ruby/internal/file_window.rb
gitlab-grit-2.7.1 lib/grit/git-ruby/internal/file_window.rb
gitlab-grit-2.6.10 lib/grit/git-ruby/internal/file_window.rb
gitlab-grit-2.7.0 lib/grit/git-ruby/internal/file_window.rb
gitlab-grit-2.6.9 lib/grit/git-ruby/internal/file_window.rb
gitlab-grit-2.6.8 lib/grit/git-ruby/internal/file_window.rb
gitlab-grit-2.6.7 lib/grit/git-ruby/internal/file_window.rb
gitlab-grit-2.6.6 lib/grit/git-ruby/internal/file_window.rb
gitlab-grit-2.6.5 lib/grit/git-ruby/internal/file_window.rb
gitlab-grit-2.6.4 lib/grit/git-ruby/internal/file_window.rb
gitlab-grit-2.6.3 lib/grit/git-ruby/internal/file_window.rb
gitlab-grit-2.6.2 lib/grit/git-ruby/internal/file_window.rb
gitlab-grit-2.5.2 lib/grit/git-ruby/internal/file_window.rb