Class: PackfileReader::PackfileEntry
- Inherits:
-
Object
- Object
- PackfileReader::PackfileEntry
- Defined in:
- lib/packfile_reader/packfile_entry.rb
Constant Summary collapse
- ZLIB_HEADERS =
ZLIB RFC: tools.ietf.org/html/rfc1950
[ 0b0111100000000001, #0x78 0x01 0b0111100010011100, #0x78 0x9c 0b0111100011011010, #0x78 0xda ]
Instance Attribute Summary collapse
-
#id ⇒ Object
readonly
Returns the value of attribute id.
-
#size ⇒ Object
readonly
Returns the value of attribute size.
-
#type ⇒ Object
readonly
Returns the value of attribute type.
Class Method Summary collapse
-
.next_entry(packfile_io, objects_to_find = :any, log_verbose = false, window_size = 10_000) ⇒ Object
Accepts a block that will receive the compressed data, uncompressed data and the computed object id.
Instance Attribute Details
#id ⇒ Object (readonly)
Returns the value of attribute id.
9 10 11 |
# File 'lib/packfile_reader/packfile_entry.rb', line 9 def id @id end |
#size ⇒ Object (readonly)
Returns the value of attribute size.
8 9 10 |
# File 'lib/packfile_reader/packfile_entry.rb', line 8 def size @size end |
#type ⇒ Object (readonly)
Returns the value of attribute type.
7 8 9 |
# File 'lib/packfile_reader/packfile_entry.rb', line 7 def type @type end |
Class Method Details
.next_entry(packfile_io, objects_to_find = :any, log_verbose = false, window_size = 10_000) ⇒ Object
Accepts a block that will receive the compressed data, uncompressed data and the computed object id. Window size is the amount of bytes to read at once while searching for the compressed data
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/packfile_reader/packfile_entry.rb', line 21 def self.next_entry(packfile_io, objects_to_find=:any, log_verbose=false, window_size=10_000) raise 'Object id must be a valid sha1' unless objects_to_find == :any || objects_to_find.all? {|id| /^[0-9a-f]{40}$/.match? id } loop do return nil if packfile_io.eof? hunk = PackfileReader::Hunk.new_with_type(packfile_io) type = hunk.type size = hunk.size offset = hunk.offset_size # Clean the current line before printing the message $stderr.puts "\u001b[0K>>>> Processing new entry [#{type}]" if log_verbose while hunk.continuation? hunk = PackfileReader::Hunk.new_without_type(packfile_io) size = (hunk.size << offset) | size # Data size is a combination of all hunk sizes offset += hunk.offset_size end compressed_data, uncompressed_data = find_data(packfile_io, log_verbose, window_size) object_id = compute_id(type, size, uncompressed_data) type = "#{type} [CORRUPTED] " if uncompressed_data.nil? if objects_to_find == :any || objects_to_find.member?(object_id) yield compressed_data, uncompressed_data, object_id if block_given? return PackfileEntry.new(type, size, object_id) end end end |