class HexaPDF::StreamData
normalized to arrays on assignment to ease further processing.
the Fiber needs to be post-processed. The filter
and decode_parms
are automatically
Additionally, the #filter and #decode_parms can be set to indicate that the data returned from
its file name or a Fiber defined via a Proc object.
(see HexaPDF::Filter). The underlying data either comes from an IO object, a file represented by
This helper class wraps all information necessary to read stream data by using a Fiber object
Container for stream data that is more complex than a string.
def ==(other)
def ==(other) other.kind_of?(StreamData) && source == other.source && offset == other.offset && length == other.length && filter == other.filter && decode_parms == other.decode_parms end
def fiber(chunk_size = 0)
def fiber(chunk_size = 0) if @source.kind_of?(FiberDoubleForString) @source.dup elsif @source.kind_of?(Proc) FiberWithLength.new(@length, &@source) elsif @source.kind_of?(String) HexaPDF::Filter.source_from_file(@source, pos: @offset || 0, length: @length || -1, chunk_size: chunk_size) else HexaPDF::Filter.source_from_io(@source, pos: @offset || 0, length: @length || -1, chunk_size: chunk_size) end end
def initialize(source = nil, offset: nil, length: nil, filter: nil, decode_parms: nil, &block)
* A Proc object (that is converted to a Fiber when needed) in which case the +offset+ and
* and for a specific +length+
* A string which is interpreted as a file name and read starting from a specific +offset+
* An IO stream which is read starting from a specific +offset+ for a specific +length+
The +source+ can be:
Creates a new StreamData object for the given +source+ and with the given options.
StreamData.new { block } -> stream_data
StreamData.new(proc) -> stream_data
StreamData.new(str) -> stream_data
StreamData.new(io) -> stream_data
:call-seq:
def initialize(source = nil, offset: nil, length: nil, filter: nil, decode_parms: nil, &block) if source.nil? && !block_given? raise ArgumentError, "Either a source object or a block must be given" end @source = source || block @offset = offset @length = length @filter = [filter].flatten.compact @decode_parms = [decode_parms].flatten freeze end