Class: Origami::Filter::Flate
- Inherits:
-
Object
- Object
- Origami::Filter::Flate
- Includes:
- Origami::Filter, Predictor
- Defined in:
- lib/origami/filters/flate.rb
Overview
Class representing a Filter used to encode and decode data with zlib/Flate compression algorithm.
Constant Summary collapse
- EOD =
:nodoc:
257
Constants included from Predictor
Predictor::NONE, Predictor::PNG_AVERAGE, Predictor::PNG_NONE, Predictor::PNG_OPTIMUM, Predictor::PNG_PAETH, Predictor::PNG_SUB, Predictor::PNG_UP, Predictor::TIFF
Constants included from Origami::Filter
Instance Method Summary collapse
-
#decode(stream) ⇒ Object
Decodes data using zlib/Inflate decompression method.
-
#encode(stream) ⇒ Object
Encodes data using zlib/Deflate compression method.
Methods included from Predictor
Methods included from Origami::Filter
Instance Method Details
#decode(stream) ⇒ Object
Decodes data using zlib/Inflate decompression method.
- stream
-
The data to decode.
51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/origami/filters/flate.rb', line 51 def decode(stream) zlib_stream = Zlib::Inflate.new begin uncompressed = zlib_stream.inflate(stream) rescue Zlib::DataError => zlib_except uncompressed = zlib_stream.flush_next_out unless Origami::OPTIONS[:ignore_zlib_errors] raise InvalidFlateDataError.new(zlib_except., input_data: stream, decoded_data: uncompressed) end end post_prediction(uncompressed) end |
#encode(stream) ⇒ Object
Encodes data using zlib/Deflate compression method.
- stream
-
The data to encode.
43 44 45 |
# File 'lib/origami/filters/flate.rb', line 43 def encode(stream) Zlib::Deflate.deflate(pre_prediction(stream), Zlib::BEST_COMPRESSION) end |