Class: GitStore::Mmap
- Inherits:
-
Object
- Object
- GitStore::Mmap
- Defined in:
- lib/git_store/pack.rb
Instance Method Summary collapse
- #[](*idx) ⇒ Object
-
#initialize(file, version = 1) ⇒ Mmap
constructor
A new instance of Mmap.
- #unmap ⇒ Object
Constructor Details
#initialize(file, version = 1) ⇒ Mmap
Returns a new instance of Mmap.
27 28 29 30 31 32 33 34 35 |
# File 'lib/git_store/pack.rb', line 27 def initialize(file, version = 1) @file = file @offset = nil if version == 2 @global_offset = 8 else @global_offset = 0 end end |
Instance Method Details
#[](*idx) ⇒ Object
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/git_store/pack.rb', line 41 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)[0] else @file.read(len) end end |
#unmap ⇒ Object
37 38 39 |
# File 'lib/git_store/pack.rb', line 37 def unmap @file = nil end |