| Class | Grit::GitRuby::Internal::FileWindow |
| In: |
lib/grit/git-ruby/internal/file_window.rb
|
| Parent: | Object |
# File lib/grit/git-ruby/internal/file_window.rb, line 16
16: def initialize(file, version = 1)
17: @file = file
18: @offset = nil
19: if version == 2
20: @global_offset = 8
21: else
22: @global_offset = 0
23: end
24: end
# File lib/grit/git-ruby/internal/file_window.rb, line 30
30: def [](*idx)
31: idx = idx[0] if idx.length == 1
32: case idx
33: when Range
34: offset = idx.first
35: len = idx.last - idx.first + idx.exclude_end? ? 0 : 1
36: when Fixnum
37: offset = idx
38: len = nil
39: when Array
40: offset, len = idx
41: else
42: raise RuntimeError, "invalid index param: #{idx.class}"
43: end
44: if @offset != offset
45: @file.seek(offset + @global_offset)
46: end
47: @offset = offset + len ? len : 1
48: if not len
49: @file.read(1).getord(0)
50: else
51: @file.read(len)
52: end
53: end