Class: PDF::Core::Stream
- Inherits:
-
Object
- Object
- PDF::Core::Stream
- Defined in:
- lib/pdf/core/stream.rb
Instance Attribute Summary collapse
-
#filters ⇒ Object
readonly
Returns the value of attribute filters.
Instance Method Summary collapse
- #<<(io) ⇒ Object
- #compress! ⇒ Object
- #compressed? ⇒ Boolean
- #data ⇒ Object
- #empty? ⇒ Boolean
- #filtered_stream ⇒ Object
-
#initialize(io = nil) ⇒ Stream
constructor
A new instance of Stream.
- #inspect ⇒ Object
- #length ⇒ Object
- #object ⇒ Object
Constructor Details
#initialize(io = nil) ⇒ Stream
Returns a new instance of Stream.
14 15 16 17 18 |
# File 'lib/pdf/core/stream.rb', line 14 def initialize(io = nil) @filtered_stream = '' @stream = io @filters = FilterList.new end |
Instance Attribute Details
#filters ⇒ Object (readonly)
Returns the value of attribute filters.
12 13 14 |
# File 'lib/pdf/core/stream.rb', line 12 def filters @filters end |
Instance Method Details
#<<(io) ⇒ Object
20 21 22 23 24 |
# File 'lib/pdf/core/stream.rb', line 20 def <<(io) (@stream ||= +'') << io @filtered_stream = nil self end |
#compress! ⇒ Object
26 27 28 29 30 31 |
# File 'lib/pdf/core/stream.rb', line 26 def compress! unless @filters.names.include? :FlateDecode @filtered_stream = nil @filters << :FlateDecode end end |
#compressed? ⇒ Boolean
33 34 35 |
# File 'lib/pdf/core/stream.rb', line 33 def compressed? @filters.names.include? :FlateDecode end |
#data ⇒ Object
71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 |
# File 'lib/pdf/core/stream.rb', line 71 def data if @stream filter_names = @filters.names filter_params = @filters.decode_params d = { Length: filtered_stream.length } if filter_names.any? d[:Filter] = filter_names end if filter_params.any? { |f| !f.nil? } d[:DecodeParms] = filter_params end d else {} end end |
#empty? ⇒ Boolean
37 38 39 |
# File 'lib/pdf/core/stream.rb', line 37 def empty? @stream.nil? end |
#filtered_stream ⇒ Object
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/pdf/core/stream.rb', line 41 def filtered_stream if @stream if @filtered_stream.nil? @filtered_stream = @stream.dup @filters.each do |(filter_name, params)| filter = PDF::Core::Filters.const_get(filter_name) if filter @filtered_stream = filter.encode @filtered_stream, params end end end @filtered_stream # XXX Fillter stream end end |
#inspect ⇒ Object
92 93 94 95 96 97 98 99 100 101 |
# File 'lib/pdf/core/stream.rb', line 92 def inspect format( '#<%<class>s:0x%<object_id>014x '\ '@stream=%<stream>s, @filters=%<filters>s>', class: self.class.name, object_id: object_id, stream: @stream.inspect, filters: @filters.inspect ) end |
#length ⇒ Object
59 60 61 |
# File 'lib/pdf/core/stream.rb', line 59 def length @stream.length end |
#object ⇒ Object
63 64 65 66 67 68 69 |
# File 'lib/pdf/core/stream.rb', line 63 def object if filtered_stream "stream\n#{filtered_stream}\nendstream\n" else '' end end |