Class: Omnizip::Algorithms::Deflate64::Encoder
- Inherits:
-
Object
- Object
- Omnizip::Algorithms::Deflate64::Encoder
- Includes:
- Constants
- Defined in:
- lib/omnizip/algorithms/deflate64/encoder.rb
Overview
Deflate64 encoder
Constant Summary
Constants included from Constants
Constants::BLOCK_TYPE_DYNAMIC, Constants::BLOCK_TYPE_FIXED, Constants::BLOCK_TYPE_STORED, Constants::DICTIONARY_SIZE, Constants::DISTANCE_CODES, Constants::END_OF_BLOCK, Constants::GOOD_MATCH, Constants::HASH_SHIFT, Constants::HASH_SIZE, Constants::LENGTH_CODES, Constants::LITERAL_CODES, Constants::MAX_CHAIN_LENGTH, Constants::MAX_DISTANCE, Constants::MAX_DISTANCE_CODE_LENGTH, Constants::MAX_LAZY_MATCH, Constants::MAX_LITERAL_CODE_LENGTH, Constants::MAX_MATCH_LENGTH, Constants::MIN_MATCH_LENGTH, Constants::NICE_MATCH
Instance Attribute Summary collapse
-
#window_size ⇒ Object
readonly
Returns the value of attribute window_size.
Instance Method Summary collapse
-
#compress(input_stream) ⇒ Object
Compress input stream to output stream.
-
#initialize(output_stream, options = {}) ⇒ Encoder
constructor
A new instance of Encoder.
Constructor Details
#initialize(output_stream, options = {}) ⇒ Encoder
Returns a new instance of Encoder.
14 15 16 17 18 19 20 |
# File 'lib/omnizip/algorithms/deflate64/encoder.rb', line 14 def initialize(output_stream, = {}) @output_stream = output_stream @window_size = [:window_size] || DICTIONARY_SIZE @compression_level = [:level] || 6 @lz77_encoder = LZ77Encoder.new(@window_size) @huffman = HuffmanCoder.new end |
Instance Attribute Details
#window_size ⇒ Object (readonly)
Returns the value of attribute window_size.
12 13 14 |
# File 'lib/omnizip/algorithms/deflate64/encoder.rb', line 12 def window_size @window_size end |
Instance Method Details
#compress(input_stream) ⇒ Object
Compress input stream to output stream
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/omnizip/algorithms/deflate64/encoder.rb', line 25 def compress(input_stream) data = input_stream.read # Step 1: LZ77 compression with 64KB window tokens = @lz77_encoder.find_matches(data) # Step 2: Huffman coding compressed = @huffman.encode(tokens) # Step 3: Serialize trees and write to output output = serialize_with_trees( compressed, @huffman.literal_tree, @huffman.distance_tree, ) @output_stream.write(output) end |