Class: Omnizip::Formats::SevenZip::Header
- Inherits:
-
Object
- Object
- Omnizip::Formats::SevenZip::Header
- Includes:
- Constants
- Defined in:
- lib/omnizip/formats/seven_zip/header.rb
Overview
.7z archive header parser Handles signature validation and start header
Constant Summary
Constants included from Constants
Constants::MAJOR_VERSION, Constants::MAX_NUM_BONDS, Constants::MAX_NUM_CODERS, Constants::MAX_NUM_PACK_STREAMS, Constants::MINOR_VERSION, Constants::SIGNATURE, Constants::SIGNATURE_SIZE, Constants::START_HEADER_SIZE
Instance Attribute Summary collapse
-
#major_version ⇒ Object
readonly
Returns the value of attribute major_version.
-
#minor_version ⇒ Object
readonly
Returns the value of attribute minor_version.
-
#next_header_crc ⇒ Object
readonly
Returns the value of attribute next_header_crc.
-
#next_header_offset ⇒ Object
readonly
Returns the value of attribute next_header_offset.
-
#next_header_size ⇒ Object
readonly
Returns the value of attribute next_header_size.
-
#start_header_crc ⇒ Object
readonly
Returns the value of attribute start_header_crc.
Class Method Summary collapse
-
.read(io) ⇒ Header
Parse header from IO.
Instance Method Summary collapse
-
#parse(io) ⇒ Object
Parse header data from IO stream.
-
#start_pos_after_header ⇒ Integer
Get position after start header.
-
#valid? ⇒ Boolean
Check if header is valid.
Instance Attribute Details
#major_version ⇒ Object (readonly)
Returns the value of attribute major_version.
11 12 13 |
# File 'lib/omnizip/formats/seven_zip/header.rb', line 11 def major_version @major_version end |
#minor_version ⇒ Object (readonly)
Returns the value of attribute minor_version.
11 12 13 |
# File 'lib/omnizip/formats/seven_zip/header.rb', line 11 def minor_version @minor_version end |
#next_header_crc ⇒ Object (readonly)
Returns the value of attribute next_header_crc.
11 12 13 |
# File 'lib/omnizip/formats/seven_zip/header.rb', line 11 def next_header_crc @next_header_crc end |
#next_header_offset ⇒ Object (readonly)
Returns the value of attribute next_header_offset.
11 12 13 |
# File 'lib/omnizip/formats/seven_zip/header.rb', line 11 def next_header_offset @next_header_offset end |
#next_header_size ⇒ Object (readonly)
Returns the value of attribute next_header_size.
11 12 13 |
# File 'lib/omnizip/formats/seven_zip/header.rb', line 11 def next_header_size @next_header_size end |
#start_header_crc ⇒ Object (readonly)
Returns the value of attribute start_header_crc.
11 12 13 |
# File 'lib/omnizip/formats/seven_zip/header.rb', line 11 def start_header_crc @start_header_crc end |
Class Method Details
.read(io) ⇒ Header
Parse header from IO
19 20 21 22 23 |
# File 'lib/omnizip/formats/seven_zip/header.rb', line 19 def self.read(io) header = new header.parse(io) header end |
Instance Method Details
#parse(io) ⇒ Object
Parse header data from IO stream
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 |
# File 'lib/omnizip/formats/seven_zip/header.rb', line 29 def parse(io) # Read complete start header (32 bytes) header_data = io.read(START_HEADER_SIZE) raise "Invalid .7z file: too short" if header_data.nil? || header_data.bytesize < START_HEADER_SIZE # Validate signature signature = header_data[0, SIGNATURE_SIZE] unless signature == SIGNATURE raise "Invalid .7z signature: expected #{SIGNATURE.inspect}, " \ "got #{signature.inspect}" end # Parse version @major_version = header_data.getbyte(6) @minor_version = header_data.getbyte(7) unless @major_version == MAJOR_VERSION raise "Unsupported .7z version: #{@major_version}.#{@minor_version}" end # Parse start header CRC (bytes 8-11) @start_header_crc = header_data[8, 4].unpack1("V") # Parse next header info (bytes 12-31, 20 bytes total) next_header_data = header_data[12, 20] # NOTE: CRC validation temporarily disabled for Phase 2 # Will be refined in Phase 3 with proper CRC32 initialization # calculated_crc = calculate_crc32(next_header_data) # unless calculated_crc == @start_header_crc # warn "CRC mismatch (non-fatal): expected " \ # "#{@start_header_crc.to_s(16)}, " \ # "got #{calculated_crc.to_s(16)}" # end # Parse next header offset and size @next_header_offset = next_header_data[0, 8].unpack1("Q<") @next_header_size = next_header_data[8, 8].unpack1("Q<") @next_header_crc = next_header_data[16, 4].unpack1("V") self end |
#start_pos_after_header ⇒ Integer
Get position after start header
76 77 78 |
# File 'lib/omnizip/formats/seven_zip/header.rb', line 76 def start_pos_after_header START_HEADER_SIZE end |
#valid? ⇒ Boolean
Check if header is valid
83 84 85 |
# File 'lib/omnizip/formats/seven_zip/header.rb', line 83 def valid? !@next_header_offset.nil? && !@next_header_size.nil? end |