Class: PDF::Core::Stream

### Home Classes Methods

### In Files

- lib/pdf/core/stream.rb

### Parent

Object

### Methods

- ::new
- #<<
- #compress!
- #compressed?
- #data
- #empty?
- #filtered_stream
- #inspect
- #length
- #object

### Class/Module Index

Quicksearch

- PDF
- PDF::Core
- PDF::Core::Errors
- PDF::Core::FilterList
- PDF::Core::Filters
- PDF::Core::Filters::DCTDecode
- PDF::Core::Filters::FlateDecode
- PDF::Core::GraphicState
- PDF::Core::GraphicStateStack
- PDF::Core::PageGeometry
- PDF::Core::Renderer
- PDF::Core::Stream

No matching classes.

# PDF::Core::Stream

### Attributes

filters[R]

### Public Class Methods

new(io = nil) click to toggle source

    # File lib/pdf/core/stream.rb, line 13
    def initialize(io = nil)
      @filtered_stream = ''
      @stream = io
      @filters = FilterList.new
    end

### Public Instance Methods

<<(io) click to toggle source

    # File lib/pdf/core/stream.rb, line 19
    def <<(io)
      (@stream ||= '') << io
      @filtered_stream = nil
      self
    end

compress!() click to toggle source

    # File lib/pdf/core/stream.rb, line 25
    def compress!
      unless @filters.names.include? :FlateDecode
        @filtered_stream = nil
        @filters << :FlateDecode
      end
    end

compressed?() click to toggle source

    # File lib/pdf/core/stream.rb, line 32
    def compressed?
      @filters.names.include? :FlateDecode
    end

data() click to toggle source

    # 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?() click to toggle source

    # File lib/pdf/core/stream.rb, line 36
    def empty?
      @stream.nil?
    end

filtered_stream() click to toggle source

    # File lib/pdf/core/stream.rb, line 40
    def filtered_stream
      if @stream
        if @filtered_stream.nil?
          @filtered_stream = @stream.dup

          @filters.each do |(filter_name, params)|
            if filter = PDF::Core::Filters.const_get(filter_name)
              @filtered_stream = filter.encode @filtered_stream, params
            end
          end
        end

        @filtered_stream
        # XXX Fillter stream
      else
        nil
      end
    end

inspect() click to toggle source

    # File lib/pdf/core/stream.rb, line 92
    def inspect
      "#<#{self.class.name}:0x#{'%014x' % object_id} @stream=#{@stream.inspect}, @filters=#{@filters.inspect}>"
    end

length() click to toggle source

    # File lib/pdf/core/stream.rb, line 59
    def length
      @stream.length
    end

object() click to toggle source

    # File lib/pdf/core/stream.rb, line 63
    def object
      if filtered_stream
        "stream\n#{filtered_stream}\nendstream\n"
      else
        ''
      end
    end

[Validate]

Generated with the Darkfish Rdoc Generator 2.