Class: Omnizip::Algorithms::Deflate::Encoder
- Inherits:
-
Object
- Object
- Omnizip::Algorithms::Deflate::Encoder
- Includes:
- Constants
- Defined in:
- lib/omnizip/algorithms/deflate/encoder.rb
Overview
Deflate encoder using Zlib
This class wraps Ruby's Zlib::Deflate to provide Deflate compression following the established Omnizip architecture.
Constant Summary
Constants included from Constants
Constants::BEST_COMPRESSION, Constants::BEST_SPEED, Constants::BUFFER_SIZE, Constants::DEFAULT_COMPRESSION, Constants::DEFAULT_STRATEGY, Constants::FILTERED, Constants::FIXED, Constants::HUFFMAN_ONLY, Constants::NO_COMPRESSION, Constants::RLE
Instance Attribute Summary collapse
-
#options ⇒ Object
readonly
Returns the value of attribute options.
-
#output_stream ⇒ Object
readonly
Returns the value of attribute output_stream.
Instance Method Summary collapse
-
#encode_stream(data) ⇒ void
Encode data stream.
-
#initialize(output_stream, options = {}) ⇒ Encoder
constructor
Initialize encoder.
Constructor Details
#initialize(output_stream, options = {}) ⇒ Encoder
Initialize encoder
24 25 26 27 28 29 30 |
# File 'lib/omnizip/algorithms/deflate/encoder.rb', line 24 def initialize(output_stream, = {}) @output_stream = output_stream @options = @level = [:level] || DEFAULT_COMPRESSION @strategy = [:strategy] || DEFAULT_STRATEGY @window_bits = [:window_bits] || 15 end |
Instance Attribute Details
#options ⇒ Object (readonly)
Returns the value of attribute options.
15 16 17 |
# File 'lib/omnizip/algorithms/deflate/encoder.rb', line 15 def @options end |
#output_stream ⇒ Object (readonly)
Returns the value of attribute output_stream.
15 16 17 |
# File 'lib/omnizip/algorithms/deflate/encoder.rb', line 15 def output_stream @output_stream end |
Instance Method Details
#encode_stream(data) ⇒ void
This method returns an undefined value.
Encode data stream
36 37 38 39 40 41 |
# File 'lib/omnizip/algorithms/deflate/encoder.rb', line 36 def encode_stream(data) deflater = Zlib::Deflate.new(@level, @window_bits, 9, @strategy) compressed = deflater.deflate(data, Zlib::FINISH) deflater.close @output_stream.write(compressed) end |