Class: Partoo::Par2File
- Inherits:
-
BinData::Record
- Object
- BinData::Record
- Partoo::Par2File
- Defined in:
- lib/partoo/par2_file.rb,
lib/partoo/par2_file/packet.rb,
lib/partoo/par2_file/packet/main.rb,
lib/partoo/par2_file/packet/creator.rb,
lib/partoo/par2_file/packet/recovery_slice.rb,
lib/partoo/par2_file/packet/file_description.rb,
lib/partoo/par2_file/packet/input_file_slice_checksum.rb
Defined Under Namespace
Classes: Packet
Instance Method Summary collapse
- #crc32_by_id(id) ⇒ Object
- #creator ⇒ Object
- #creator_packet ⇒ Object
- #file_description_packet_by_id(id) ⇒ Object
- #file_ids ⇒ Object
- #input_file_slice_checksum_packet_by_id(id) ⇒ Object
- #list ⇒ Object
- #main_packet ⇒ Object
- #recovery_set_file_count ⇒ Object
- #recovery_set_id ⇒ Object
- #slice_size ⇒ Object
Instance Method Details
#crc32_by_id(id) ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/partoo/par2_file.rb', line 18 def crc32_by_id(id) crc = "" input_file_slice_checksum_packet_by_id(id)[0]['body']['chunk_checksums'].each do |cc| crc_b = cc['crc32'] if crc != "" crc = Zlib.crc32_combine(crc, crc_b, slice_size) else crc = crc_b end end pad_length = slice_size - file_description_packet_by_id(id)[0]['body'].file_length % slice_size crc_z = Zlib.crc32("\0" * pad_length) Partoo::CRC32.crc32_trim_trailing(crc, crc_z, pad_length) end |
#creator ⇒ Object
33 34 35 |
# File 'lib/partoo/par2_file.rb', line 33 def creator creator_packet[0]['body']['creator'] end |
#creator_packet ⇒ Object
53 54 55 |
# File 'lib/partoo/par2_file.rb', line 53 def creator_packet packets.select {|p| p['packet_type'] == "PAR 2.0\0Creator\0" } end |
#file_description_packet_by_id(id) ⇒ Object
57 58 59 |
# File 'lib/partoo/par2_file.rb', line 57 def file_description_packet_by_id(id) packets.select {|p| p['packet_type'] == "PAR 2.0\0FileDesc" && p['body']['file_id'] == id } end |
#file_ids ⇒ Object
37 38 39 |
# File 'lib/partoo/par2_file.rb', line 37 def file_ids main_packet[0]['body']['file_ids'] end |
#input_file_slice_checksum_packet_by_id(id) ⇒ Object
61 62 63 |
# File 'lib/partoo/par2_file.rb', line 61 def input_file_slice_checksum_packet_by_id(id) packets.select {|p| p['packet_type'] == "PAR 2.0\0IFSC\0\0\0\0" && p['body']['file_id'] == id } end |
#list ⇒ Object
12 13 14 15 16 |
# File 'lib/partoo/par2_file.rb', line 12 def list file_ids.map do |id| [file_description_packet_by_id(id)[0]['body'], {:file_crc32 => crc32_by_id(id)}] end end |
#main_packet ⇒ Object
65 66 67 |
# File 'lib/partoo/par2_file.rb', line 65 def main_packet packets.select {|p| p['packet_type'] == "PAR 2.0\0Main\0\0\0\0" } end |
#recovery_set_file_count ⇒ Object
45 46 47 |
# File 'lib/partoo/par2_file.rb', line 45 def recovery_set_file_count main_packet[0]['body']['recovery_set_file_count'] end |
#recovery_set_id ⇒ Object
49 50 51 |
# File 'lib/partoo/par2_file.rb', line 49 def recovery_set_id main_packet[0]['recovery_set_id'] end |
#slice_size ⇒ Object
41 42 43 |
# File 'lib/partoo/par2_file.rb', line 41 def slice_size main_packet[0]['body']['slice_size'] end |