Class Origami::Stream
In: sources/parser/stream.rb
sources/parser/obfuscation.rb
Parent: Object

Class representing a PDF Stream Object. Streams can be used to hold any kind of data, especially binary data.

Methods

Included Modules

Origami::Object Configurable

Constants

Length = @rawdata.length
Length = @rawdata.length

Attributes

dictionary  [RW] 

Public Class methods

Creates a new PDF Stream.

data:The Stream uncompressed data.
dictionary:A hash representing the Stream attributes.

[Source]

    # File sources/parser/stream.rb, line 75
75:     def initialize(data = "", dictionary = {})
76:       
77:         super(true)
78:        
79:         @dictionary, @data = Dictionary.new(dictionary), data
80:         @dictionary.parent = self
81:     end

Public Instance methods

Returns the uncompressed stream content.

[Source]

     # File sources/parser/stream.rb, line 162
162:     def data
163:       self.decode! if @data.nil?
164:       
165:       @data 
166:     end

Sets the uncompressed stream content.

str:The new uncompressed data.

[Source]

     # File sources/parser/stream.rb, line 172
172:     def data=(str)      
173:       @rawdata = nil
174:       @data = str
175:     end

Uncompress the stream data.

[Source]

     # File sources/parser/stream.rb, line 198
198:     def decode!
199:       
200:       if @rawdata
201:       
202:         filters = @dictionary[:Filter]
203:         
204:         if filters.nil?
205:           @data = @rawdata
206:         elsif filters.type == :Array
207:           
208:           @data = @rawdata
209:           
210:           filters.each { |filter|
211:             @data = decodedata(@data, filter)
212:           }
213:           
214:         elsif filters.type == :Name
215:           
216:           @data = decodedata(@rawdata, filters)
217:         else
218:           raise InvalidStream, "Invalid Filter type parameter"
219:         end
220:         
221:       end
222:       
223:       self
224:     end

Compress the stream data.

[Source]

     # File sources/parser/stream.rb, line 229
229:     def encode!
230:       
231:       if @data
232:       
233:         filters = @dictionary[:Filter]
234:         
235:         if filters.nil?
236:           @rawdata = @data
237:         elsif filters.is_a?(Array)
238:           
239:           @rawdata = @data
240:           
241:           filters.to_a.reverse.each { |filter|
242:             @rawdata = encodedata(@rawdata, filter)
243:           }
244:         
245:         elsif filters.is_a?(Name)
246:           
247:           @rawdata = encodedata(@data, filters)
248:           
249:         else
250:           raise InvalidStream, "Invalid filter type parameter"
251:         end
252:         
253:         self.Length = @rawdata.length
254:       
255:       end
256:       
257:       self
258:     end

[Source]

    # File sources/parser/stream.rb, line 90
90:     def post_build
91:      
92:       unless self.Length.nil?
93:         self.Length = @rawdata.length
94:       end
95:  
96:       super
97:     end

[Source]

    # File sources/parser/stream.rb, line 83
83:     def pre_build
84:       set_indirect(true)
85:       encode!
86:      
87:       super
88:     end

Returns the raw compressed stream content.

[Source]

     # File sources/parser/stream.rb, line 180
180:     def rawdata
181:       self.encode! if @rawdata.nil? 
182:        
183:       @rawdata
184:     end

Sets the raw compressed stream content.

str:the new raw data.

[Source]

     # File sources/parser/stream.rb, line 190
190:     def rawdata=(str)
191:       @rawdata = str
192:       @data = nil
193:     end

[Source]

     # File sources/parser/stream.rb, line 285
285:     def real_type ; Stream end

[Source]

     # File sources/parser/stream.rb, line 138
138:     def set_predictor(predictor, colors = 1, bitspercomponent = 8, columns = 1)
139:       
140:       filters = @dictionary[:Filter].is_a?(::Array) ? filters : [ @dictionary[:Filter] ]
141: 
142:       if not filters.include?(:FlateDecode) and not filters.include?(:LZWDecode)
143:         raise InvalidStream, 'Predictor functions can only be used with Flate or LZW filters'
144:       end
145: 
146:       params = @dictionary[:DecodeParms] ||= Filter::LZW::DecodeParms.new
147:       params[:Predictor] = predictor
148:       params[:Colors] = colors if colors != 1
149:       params[:BitsPerComponent] = bitspercomponent if bitspercomponent != 8
150:       params[:Columns] = columns if columns != 1
151: 
152:       self
153:     end

[Source]

     # File sources/parser/obfuscation.rb, line 202
202:     def to_obfuscated_str
203:       content = ""
204:       
205:       content << @dictionary.to_obfuscated_str
206:       content << "stream" + EOL
207:       content << self.rawdata
208:       content << EOL << TOKENS.last
209:       
210:       print(content)
211:     end

[Validate]