Class: Pack::Reader
- Inherits:
-
Object
- Object
- Pack::Reader
- Defined in:
- lib/pack/reader.rb
Instance Attribute Summary collapse
-
#count ⇒ Object
readonly
Returns the value of attribute count.
Instance Method Summary collapse
-
#initialize(input) ⇒ Reader
constructor
A new instance of Reader.
- #read_header ⇒ Object
- #read_info ⇒ Object
- #read_record ⇒ Object
Constructor Details
#initialize(input) ⇒ Reader
Returns a new instance of Reader.
11 12 13 |
# File 'lib/pack/reader.rb', line 11 def initialize(input) @input = input end |
Instance Attribute Details
#count ⇒ Object (readonly)
Returns the value of attribute count.
9 10 11 |
# File 'lib/pack/reader.rb', line 9 def count @count end |
Instance Method Details
#read_header ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/pack/reader.rb', line 15 def read_header data = @input.read(HEADER_SIZE) signature, version, @count = data.unpack(HEADER_FORMAT) unless signature == SIGNATURE raise InvalidPack, "bad pack signature: #{ signature }" end unless version == VERSION raise InvalidPack, "unsupported pack version: #{ version }" end end |
#read_info ⇒ Object
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/pack/reader.rb', line 41 def read_info type, size = read_record_header case type when COMMIT, TREE, BLOB Record.new(TYPE_CODES.key(type), size) when OFS_DELTA delta = read_ofs_delta size = Expander.new(delta.delta_data).target_size OfsDelta.new(delta.base_ofs, size) when REF_DELTA delta = read_ref_delta size = Expander.new(delta.delta_data).target_size RefDelta.new(delta.base_oid, size) end end |