class Partoo::Par2File

Public Instance Methods

crc32_by_id(id) click to toggle source
# File lib/partoo/par2_file.rb, line 34
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() click to toggle source
# File lib/partoo/par2_file.rb, line 49
def creator
  creator_packet[0]['body']['creator']
end
creator_packet() click to toggle source
# File lib/partoo/par2_file.rb, line 71
def creator_packet
  packets.select {|p| p['packet_type'] == "PAR 2.0\0Creator\0" }
end
file_description_packet_by_id(id) click to toggle source
# File lib/partoo/par2_file.rb, line 75
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() click to toggle source
# File lib/partoo/par2_file.rb, line 53
def file_ids
  main_packet[0]['body']['file_ids'].sort_by do |id|
    file_description_packet_by_id(id)[0]['body']['file_name']
  end
end
input_file_slice_checksum_packet_by_id(id) click to toggle source
# File lib/partoo/par2_file.rb, line 79
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() click to toggle source
# 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() click to toggle source
# File lib/partoo/par2_file.rb, line 83
def main_packet
  packets.select {|p| p['packet_type'] == "PAR 2.0\0Main\0\0\0\0" }
end
recovery_set_file_count() click to toggle source
# File lib/partoo/par2_file.rb, line 63
def recovery_set_file_count
  main_packet[0]['body']['recovery_set_file_count']
end
recovery_set_id() click to toggle source
# File lib/partoo/par2_file.rb, line 67
def recovery_set_id
  main_packet[0]['recovery_set_id']
end
slice_size() click to toggle source
# File lib/partoo/par2_file.rb, line 59
def slice_size
  main_packet[0]['body']['slice_size']
end
to_md5() click to toggle source
# File lib/partoo/par2_file.rb, line 18
def to_md5
  file_ids.map do |id|
    file_description_packet_by_id(id)[0]['body']['file_md5'].to_hex
      .concat('  ')
      .concat(file_description_packet_by_id(id)[0]['body']['file_name'])
  end.join("\n").concat("\n")
end
to_sfv() click to toggle source
# File lib/partoo/par2_file.rb, line 26
def to_sfv
  file_ids.map do |id|
    file_description_packet_by_id(id)[0]['body']['file_name']
      .concat(' ')
      .concat(crc32_by_id(id).to_s(16).rjust(8, '0'))
  end.join("\n").concat("\n")
end