Class: Origami::Filter::Flate

Inherits:
Object
  • Object
show all
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

A85, AHx, CCF, Fl, RL

Instance Method Summary collapse

Methods included from Predictor

included, #initialize

Methods included from Origami::Filter

included, #initialize

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.message, 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