Class: PDF::Reader::Filter::Flate

Inherits:
Object
  • Object
show all
Defined in:
lib/pdf/reader/filter/flate.rb

Overview

implementation of the Flate (zlib) stream filter

Constant Summary collapse

ZLIB_AUTO_DETECT_ZLIB_OR_GZIP =

Zlib::MAX_WBITS + 32

47
ZLIB_RAW_DEFLATE =

Zlib::MAX_WBITS * -1

-15 # Zlib::MAX_WBITS * -1

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Flate

Returns a new instance of Flate.



16
17
18
# File 'lib/pdf/reader/filter/flate.rb', line 16

def initialize(options = {})
  @options = options
end

Instance Method Details

#filter(data) ⇒ Object

Decode the specified data with the Zlib compression algorithm



22
23
24
25
26
27
28
29
30
# File 'lib/pdf/reader/filter/flate.rb', line 22

def filter(data)
  deflated = zlib_inflate(data) || zlib_inflate(data[0, data.bytesize-1])

  if deflated.nil?
    raise MalformedPDFError,
      "Error while inflating a compressed stream (no suitable inflation algorithm found)"
  end
  Depredict.new(@options).filter(deflated)
end