Class: Omnizip::Algorithms::XZLZMA2
- Inherits:
-
Omnizip::Algorithm
- Object
- Omnizip::Algorithm
- Omnizip::Algorithms::XZLZMA2
- Defined in:
- lib/omnizip/algorithms/xz_lzma2.rb
Overview
XZ Utils LZMA2 compression algorithm.
This algorithm uses the XZ Utils implementation of LZMA2, which provides full compatibility with xz command-line tools.
Instance Attribute Summary
Attributes inherited from Omnizip::Algorithm
Class Method Summary collapse
-
.metadata ⇒ Models::AlgorithmMetadata
Get algorithm metadata.
Instance Method Summary collapse
-
#compress(input, output) ⇒ void
Compress data using XZ Utils LZMA2.
-
#decompress(input, output) ⇒ void
Decompress data using XZ Utils LZMA2.
Methods inherited from Omnizip::Algorithm
inherited, #initialize, #with_filter
Constructor Details
This class inherits a constructor from Omnizip::Algorithm
Class Method Details
.metadata ⇒ Models::AlgorithmMetadata
Get algorithm metadata.
43 44 45 46 47 48 49 |
# File 'lib/omnizip/algorithms/xz_lzma2.rb', line 43 def self. Models::AlgorithmMetadata.new.tap do || .name = "xz_lzma2" .description = "LZMA2 compression (XZ Utils implementation)" .version = "1.0.0" end end |
Instance Method Details
#compress(input, output) ⇒ void
This method returns an undefined value.
Compress data using XZ Utils LZMA2.
56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 |
# File 'lib/omnizip/algorithms/xz_lzma2.rb', line 56 def compress(input, output) input_data = if input.is_a?(String) input elsif input.respond_to?(:read) input.read else raise ArgumentError, "Input must be a String or IO" end # Apply filter if set if @filter input_data = @filter.encode(input_data) end # Get encoding options dict_size = @options.fetch(:dict_size, 8 * 1024 * 1024) lc = @options.fetch(:lc, 3) lp = @options.fetch(:lp, 0) pb = @options.fetch(:pb, 2) standalone = @options.fetch(:standalone, false) # Create encoder and compress encoder = Implementations::XZUtils::LZMA2::Encoder.new( dict_size: dict_size, lc: lc, lp: lp, pb: pb, standalone: standalone, ) compressed = encoder.encode(input_data) output.write(compressed) end |
#decompress(input, output) ⇒ void
This method returns an undefined value.
Decompress data using XZ Utils LZMA2.
95 96 97 98 99 100 101 102 103 104 105 106 107 108 |
# File 'lib/omnizip/algorithms/xz_lzma2.rb', line 95 def decompress(input, output) dict_size = @options.fetch(:dict_size, 8 * 1024 * 1024) decoder = Implementations::XZUtils::LZMA2::Decoder.new(input, raw_mode: true, dict_size: dict_size) decompressed = decoder.decode_stream # Reverse filter if set if @filter decompressed = @filter.decode(decompressed) end output.write(decompressed) end |