Class: Omnizip::Formats::XzImpl::StreamFooter
- Inherits:
-
Object
- Object
- Omnizip::Formats::XzImpl::StreamFooter
- Includes:
- Omnizip::Formats::XzConst
- Defined in:
- lib/omnizip/formats/xz_impl/stream_footer.rb
Overview
XZ Stream Footer encoder Based on XZ Utils stream_flags_encoder.c
Constant Summary
Constants included from Omnizip::Formats::XzConst
Omnizip::Formats::XzConst::BACKWARD_SIZE_MAX, Omnizip::Formats::XzConst::BACKWARD_SIZE_MIN, Omnizip::Formats::XzConst::BLOCK_HEADER_SIZE_MAX, Omnizip::Formats::XzConst::BLOCK_HEADER_SIZE_MIN, Omnizip::Formats::XzConst::CHECK_CRC32, Omnizip::Formats::XzConst::CHECK_CRC64, Omnizip::Formats::XzConst::CHECK_NONE, Omnizip::Formats::XzConst::CHECK_SHA256, Omnizip::Formats::XzConst::FILTERS_MAX, Omnizip::Formats::XzConst::FILTER_LZMA2, Omnizip::Formats::XzConst::FOOTER_MAGIC, Omnizip::Formats::XzConst::INDEX_INDICATOR, Omnizip::Formats::XzConst::MAGIC, Omnizip::Formats::XzConst::STREAM_FLAGS_SIZE, Omnizip::Formats::XzConst::STREAM_FOOTER_SIZE, Omnizip::Formats::XzConst::STREAM_HEADER_SIZE, Omnizip::Formats::XzConst::VLI_BYTES_MAX, Omnizip::Formats::XzConst::VLI_UNKNOWN
Instance Attribute Summary collapse
-
#backward_size ⇒ Object
readonly
Returns the value of attribute backward_size.
-
#check_type ⇒ Object
readonly
Returns the value of attribute check_type.
Instance Method Summary collapse
-
#encode ⇒ Object
Encode stream footer (12 bytes total) Format: - CRC32 (4 bytes): CRC32 of backward size + stream flags - Backward Size (4 bytes): Size of Index in 4-byte multiples - Stream Flags (2 bytes): version + check type - Footer Magic (2 bytes): 59 5A.
-
#initialize(backward_size:, check_type: CHECK_CRC64) ⇒ StreamFooter
constructor
A new instance of StreamFooter.
Constructor Details
#initialize(backward_size:, check_type: CHECK_CRC64) ⇒ StreamFooter
Returns a new instance of StreamFooter.
15 16 17 18 |
# File 'lib/omnizip/formats/xz_impl/stream_footer.rb', line 15 def initialize(backward_size:, check_type: CHECK_CRC64) @check_type = check_type @backward_size = backward_size end |
Instance Attribute Details
#backward_size ⇒ Object (readonly)
Returns the value of attribute backward_size.
13 14 15 |
# File 'lib/omnizip/formats/xz_impl/stream_footer.rb', line 13 def backward_size @backward_size end |
#check_type ⇒ Object (readonly)
Returns the value of attribute check_type.
13 14 15 |
# File 'lib/omnizip/formats/xz_impl/stream_footer.rb', line 13 def check_type @check_type end |
Instance Method Details
#encode ⇒ Object
Encode stream footer (12 bytes total) Format:
- CRC32 (4 bytes): CRC32 of backward size + stream flags
- Backward Size (4 bytes): Size of Index in 4-byte multiples
- Stream Flags (2 bytes): version + check type
- Footer Magic (2 bytes): 59 5A
26 27 28 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 |
# File 'lib/omnizip/formats/xz_impl/stream_footer.rb', line 26 def encode output = String.new(encoding: Encoding::BINARY) # Validate backward size unless valid_backward_size? raise ArgumentError, "Invalid backward size: #{@backward_size}" end # Encode backward size (stored as (bytes / 4) - 1) backward_encoded = (@backward_size / 4) - 1 backward_bytes = [backward_encoded].pack("V") # Little-endian uint32 # Encode stream flags flags = encode_stream_flags # Calculate CRC32 of backward size + flags crc_data = backward_bytes + flags crc = Zlib.crc32(crc_data) # Write CRC32 output << [crc].pack("V") # Write backward size output << backward_bytes # Write stream flags output << flags # Write footer magic output << FOOTER_MAGIC.pack("C*") output end |