Class: Omnizip::Formats::Rar::Rar5::Header

Inherits:
Object
  • Object
show all
Defined in:
lib/omnizip/formats/rar/rar5/header.rb

Overview

Base class for RAR5 headers

Direct Known Subclasses

EndHeader, FileHeader, MainHeader

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(type, flags: 0, extra_area: nil, data_area_size: nil, header_data: "") ⇒ Header

Returns a new instance of Header.



22
23
24
25
26
27
28
29
30
31
# File 'lib/omnizip/formats/rar/rar5/header.rb', line 22

def initialize(type, flags: 0, extra_area: nil, data_area_size: nil,
header_data: "")
  @type = type
  @flags = flags
  @flags |= FLAG_EXTRA_AREA if extra_area
  @flags |= FLAG_DATA_AREA if data_area_size
  @extra_area = extra_area
  @data_area_size = data_area_size
  @header_data = header_data
end

Instance Attribute Details

#data_area_sizeObject (readonly)

Returns the value of attribute data_area_size.



20
21
22
# File 'lib/omnizip/formats/rar/rar5/header.rb', line 20

def data_area_size
  @data_area_size
end

#extra_areaObject (readonly)

Returns the value of attribute extra_area.



20
21
22
# File 'lib/omnizip/formats/rar/rar5/header.rb', line 20

def extra_area
  @extra_area
end

#flagsObject (readonly)

Returns the value of attribute flags.



20
21
22
# File 'lib/omnizip/formats/rar/rar5/header.rb', line 20

def flags
  @flags
end

#header_dataObject (readonly)

Returns the value of attribute header_data.



20
21
22
# File 'lib/omnizip/formats/rar/rar5/header.rb', line 20

def header_data
  @header_data
end

#typeObject (readonly)

Returns the value of attribute type.



20
21
22
# File 'lib/omnizip/formats/rar/rar5/header.rb', line 20

def type
  @type
end

Instance Method Details

#encodeObject



33
34
35
36
37
38
39
40
41
42
# File 'lib/omnizip/formats/rar/rar5/header.rb', line 33

def encode
  # Build header without CRC
  header_bytes = build_header_bytes

  # Calculate CRC32
  crc = CRC32.calculate(header_bytes.pack("C*"))

  # Prepend CRC (little-endian)
  [crc].pack("V") + header_bytes.pack("C*")
end