Class: Omnizip::Algorithms::LZMA2::LZMA2Chunk
- Inherits:
-
Object
- Object
- Omnizip::Algorithms::LZMA2::LZMA2Chunk
- Defined in:
- lib/omnizip/algorithms/lzma2/lzma2_chunk.rb
Overview
LZMA2 Chunk structure using Array#pack for binary serialization
Constant Summary collapse
- TYPE_END =
:end- TYPE_UNCOMPRESSED =
:uncompressed- TYPE_COMPRESSED =
:compressed
Instance Attribute Summary collapse
-
#chunk_type ⇒ Object
readonly
Returns the value of attribute chunk_type.
-
#compressed_data ⇒ Object
readonly
Returns the value of attribute compressed_data.
-
#control_byte ⇒ Object
readonly
Returns the value of attribute control_byte.
-
#properties ⇒ Object
readonly
Returns the value of attribute properties.
-
#uncompressed_data ⇒ Object
readonly
Returns the value of attribute uncompressed_data.
Class Method Summary collapse
-
.end_chunk ⇒ Object
Factory method for end marker.
Instance Method Summary collapse
-
#initialize(chunk_type:, need_dict_reset:, need_state_reset:, need_props:, uncompressed_data: "", compressed_data: "", properties: nil, compressed_size: nil) ⇒ LZMA2Chunk
constructor
A new instance of LZMA2Chunk.
-
#to_bytes ⇒ Object
Serialize to binary format.
Constructor Details
#initialize(chunk_type:, need_dict_reset:, need_state_reset:, need_props:, uncompressed_data: "", compressed_data: "", properties: nil, compressed_size: nil) ⇒ LZMA2Chunk
Returns a new instance of LZMA2Chunk.
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 |
# File 'lib/omnizip/algorithms/lzma2/lzma2_chunk.rb', line 27 def initialize(chunk_type:, need_dict_reset:, need_state_reset:, need_props:, uncompressed_data: "", compressed_data: "", properties: nil, compressed_size: nil) # Validate chunk_type valid_types = [TYPE_END, TYPE_UNCOMPRESSED, TYPE_COMPRESSED] unless valid_types.include?(chunk_type) raise ArgumentError, "Invalid chunk_type: #{chunk_type.inspect}. " \ "Must be :end, :uncompressed, or :compressed" end @chunk_type = chunk_type @uncompressed_data = uncompressed_data @compressed_data = compressed_data # For XZ format, compressed_size excludes flush bytes # For standalone LZMA2, compressed_size includes all bytes @compressed_size = compressed_size || @compressed_data.bytesize @properties = properties @need_dict_reset = need_dict_reset @need_state_reset = need_state_reset @need_props = need_props @control_byte = build_control_byte if chunk_type != TYPE_END end |
Instance Attribute Details
#chunk_type ⇒ Object (readonly)
Returns the value of attribute chunk_type.
12 13 14 |
# File 'lib/omnizip/algorithms/lzma2/lzma2_chunk.rb', line 12 def chunk_type @chunk_type end |
#compressed_data ⇒ Object (readonly)
Returns the value of attribute compressed_data.
12 13 14 |
# File 'lib/omnizip/algorithms/lzma2/lzma2_chunk.rb', line 12 def compressed_data @compressed_data end |
#control_byte ⇒ Object (readonly)
Returns the value of attribute control_byte.
12 13 14 |
# File 'lib/omnizip/algorithms/lzma2/lzma2_chunk.rb', line 12 def control_byte @control_byte end |
#properties ⇒ Object (readonly)
Returns the value of attribute properties.
12 13 14 |
# File 'lib/omnizip/algorithms/lzma2/lzma2_chunk.rb', line 12 def properties @properties end |
#uncompressed_data ⇒ Object (readonly)
Returns the value of attribute uncompressed_data.
12 13 14 |
# File 'lib/omnizip/algorithms/lzma2/lzma2_chunk.rb', line 12 def uncompressed_data @uncompressed_data end |
Class Method Details
.end_chunk ⇒ Object
Factory method for end marker
16 17 18 19 20 21 22 23 24 25 |
# File 'lib/omnizip/algorithms/lzma2/lzma2_chunk.rb', line 16 def self.end_chunk new( chunk_type: TYPE_END, uncompressed_data: "", compressed_data: "", need_dict_reset: false, need_state_reset: false, need_props: false, ) end |
Instance Method Details
#to_bytes ⇒ Object
Serialize to binary format
54 55 56 57 58 59 60 61 62 63 |
# File 'lib/omnizip/algorithms/lzma2/lzma2_chunk.rb', line 54 def to_bytes case @chunk_type when TYPE_END [0x00].pack("C") when TYPE_UNCOMPRESSED serialize_uncompressed when TYPE_COMPRESSED serialize_compressed end end |