Sha256: 3e4496a7b3ed6b480c8875bcc054021024564e6eb2759c6dbbeacdf1e9336de7

Contents?: true

Size: 1020 Bytes

Versions: 10

Compression:

Stored size: 1020 Bytes

Contents

# coding: utf-8
# frozen_string_literal: true

class PDF::Reader

  # provides a wrapper around a PDF stream object that contains other objects in it.
  # This is done for added compression and is described as an "Object Stream" in the spec.
  #
  class ObjectStream # :nodoc:
    def initialize(stream)
      @dict = stream.hash
      @data = stream.unfiltered_data
    end

    def [](objid)
      if offsets[objid].nil?
        nil
      else
        buf = PDF::Reader::Buffer.new(StringIO.new(@data), :seek => offsets[objid])
        parser = PDF::Reader::Parser.new(buf)
        parser.parse_token
      end
    end

    def size
      @dict[:N]
    end

    private

    def offsets
      @offsets ||= {}
      return @offsets if @offsets.keys.size > 0

      size.times do
        @offsets[buffer.token.to_i] = first + buffer.token.to_i
      end
      @offsets
    end

    def first
      @dict[:First]
    end

    def buffer
      @buffer ||= PDF::Reader::Buffer.new(StringIO.new(@data))
    end

  end

end

Version data entries

10 entries across 9 versions & 2 rubygems

Version Path
pdf-reader-2.6.0 lib/pdf/reader/object_stream.rb
pdf-reader-2.5.0 lib/pdf/reader/object_stream.rb
pdf-reader-2.4.2 lib/pdf/reader/object_stream.rb
pdf-reader-2.4.1 lib/pdf/reader/object_stream.rb
pdf-reader-2.4.0 lib/pdf/reader/object_stream.rb
pdf-reader-2.3.0 lib/pdf/reader/object_stream.rb
pdf-reader-2.2.1 lib/pdf/reader/object_stream.rb
embulk-input-druginfo_interview_form-0.1.0 vendor/bundle/ruby/2.4.0/gems/pdf-reader-2.2.0/lib/pdf/reader/object_stream.rb
embulk-input-druginfo_interview_form-0.1.0 vendor/bundle/ruby/2.5.0/gems/pdf-reader-2.2.0/lib/pdf/reader/object_stream.rb
pdf-reader-2.2.0 lib/pdf/reader/object_stream.rb