Class: Omnizip::Algorithms::SevenZipLZMA2
- Inherits:
-
Omnizip::Algorithm
- Object
- Omnizip::Algorithm
- Omnizip::Algorithms::SevenZipLZMA2
- Defined in:
- lib/omnizip/algorithms/sevenzip_lzma2.rb
Overview
7-Zip LZMA2 compression algorithm.
This algorithm uses the 7-Zip SDK-compatible implementation of LZMA2, which provides compatibility with 7-Zip 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 7-Zip LZMA2.
-
#decompress(input, output) ⇒ void
Decompress data using 7-Zip 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/sevenzip_lzma2.rb', line 43 def self. Models::AlgorithmMetadata.new.tap do || .name = "sevenzip_lzma2" .description = "LZMA2 compression (7-Zip SDK implementation)" .version = "1.0.0" end end |
Instance Method Details
#compress(input, output) ⇒ void
This method returns an undefined value.
Compress data using 7-Zip 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 89 90 91 92 |
# File 'lib/omnizip/algorithms/sevenzip_lzma2.rb', line 56 def compress(input, output) # Apply filter if set input_data = if input.is_a?(String) if @filter @filter.encode(input) else input end elsif input.respond_to?(:read) data = input.read if @filter @filter.encode(data) else data end else raise ArgumentError, "Input must be a String or IO" 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) # Use existing LZMA2Encoder which wraps SimpleLZMA2Encoder encoder = LZMA2::LZMA2Encoder.new( dict_size: dict_size, lc: lc, lp: lp, pb: pb, standalone: false, ) compressed = encoder.encode(input_data) output.write(compressed) end |
#decompress(input, output) ⇒ void
This method returns an undefined value.
Decompress data using 7-Zip LZMA2.
99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 |
# File 'lib/omnizip/algorithms/sevenzip_lzma2.rb', line 99 def decompress(input, output) dict_size = @options.fetch(:dict_size, 8 * 1024 * 1024) # Use existing LZMA2::Decoder decoder = 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 |