Class: PDF::Reader::Stream

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

Overview

An internal PDF::Reader class that represents a stream object from a PDF. Stream objects have 2 components, a dictionary that describes the content (size, compression, etc) and a stream of bytes.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(hash, data) ⇒ Stream

Creates a new stream with the specified dictionary and data. The dictionary should be a standard ruby hash, the data should be a standard ruby string.


41
42
43
44
45
# File 'lib/pdf/reader/stream.rb', line 41

def initialize(hash, data)
  @hash = hash
  @data = data
  @udata = nil
end

Instance Attribute Details

#dataObject

Returns the value of attribute data


36
37
38
# File 'lib/pdf/reader/stream.rb', line 36

def data
  @data
end

#hashObject

Returns the value of attribute hash


36
37
38
# File 'lib/pdf/reader/stream.rb', line 36

def hash
  @hash
end

Instance Method Details

#unfiltered_dataObject

apply this streams filters to its data and return the result.


48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
# File 'lib/pdf/reader/stream.rb', line 48

def unfiltered_data
  return @udata if @udata
  @udata = data.dup

  if hash.has_key?(:Filter)
    options = []

    if hash.has_key?(:DecodeParms)
      if hash[:DecodeParms].is_a?(Hash)
        options = [hash[:DecodeParms]]
      else
        options = hash[:DecodeParms]
      end
    end

    Array(hash[:Filter]).each_with_index do |filter, index|
      @udata = Filter.with(filter, options[index]).filter(@udata)
    end
  end
  @udata
end