Class: Omnizip::Parity::Models::CreatorPacket

Inherits:
Packet
  • Object
show all
Defined in:
lib/omnizip/parity/models/creator_packet.rb

Overview

PAR2 Creator packet

Contains information about the tool that created the PAR2 file. This packet is optional but recommended for identification.

Body structure:

  • creator_string (variable): Null-terminated string identifying the tool

Constant Summary collapse

PACKET_TYPE =

Packet type identifier

"PAR 2.0\x00Creator\x00"

Constants inherited from Packet

Packet::PACKET_SIGNATURE

Instance Attribute Summary

Attributes inherited from Packet

#body_data

Instance Method Summary collapse

Methods inherited from Packet

#calculate_hash, #packet_type, read_from, #valid_hash?, #write_to

Constructor Details

#initialize(**attributes) ⇒ CreatorPacket

Initialize creator packet

Parameters:

  • attributes (Hash)

    Packet attributes



23
24
25
26
# File 'lib/omnizip/parity/models/creator_packet.rb', line 23

def initialize(**attributes)
  super
  self.type = PACKET_TYPE
end

Instance Method Details

#build_bodyString

Build body data from attributes

Constructs binary body data with null terminator

Returns:

  • (String)

    Binary body data



44
45
46
47
48
49
50
51
52
# File 'lib/omnizip/parity/models/creator_packet.rb', line 44

def build_body
  data = +""

  # Write creator string (null-terminated)
  data << creator_string
  data << "\x00"

  self.body_data = data
end

#parse_bodyObject

Parse body data into attributes

Body format:

  • creator_string: null-terminated string


32
33
34
35
36
37
# File 'lib/omnizip/parity/models/creator_packet.rb', line 32

def parse_body
  return if body_data.nil? || body_data.empty?

  # Read creator string (null-terminated)
  self.creator_string = body_data.unpack1("Z*")
end

#tool_nameString

Get creator tool name

Returns:

  • (String)

    Creator tool name



57
58
59
# File 'lib/omnizip/parity/models/creator_packet.rb', line 57

def tool_name
  creator_string.split.first || creator_string
end

#versionString?

Get creator version if available

Returns:

  • (String, nil)

    Version string or nil



64
65
66
67
# File 'lib/omnizip/parity/models/creator_packet.rb', line 64

def version
  parts = creator_string.split
  parts.size > 1 ? parts[1..].join(" ") : nil
end