class IOP::IOReader
Feed
class to read data from external IO
stream and send it in blocks downstream.
Contrary to {FileReader}, this class does not manage attached IO
instance, e.g. it makes no attempt to close it after processing.
### Use case: sequential read of two 1024-byte blocks from the same IO
stream.
require 'iop/file' require 'iop/string' io = File.new('input.dat', 'rb') begin ( IOP::IOReader.new(io, size: 1024) | (first = IOP::StringMerger.new) ).process! ( IOP::IOReader.new(io, size: 1024, offset: 1024) | (second = IOP::StringMerger.new) ).process! ensure io.close end puts first.to_s puts second.to_s
@since 0.1
Public Class Methods
new(io, **options)
click to toggle source
Creates class instance.
@param io [IO] IO
instance to read data from
@param options [Hash] keyword arguments passed to {RandomAccessReader} constructor
Calls superclass method
IOP::RandomAccessReader::new
# File lib/iop/file.rb, line 36 def initialize(io, **options) super(**options) @io = io end
Private Instance Methods
read!(read_size, data)
click to toggle source
# File lib/iop/file.rb, line 45 def read!(read_size, data) @io.read(read_size, data) end
seek!()
click to toggle source
# File lib/iop/file.rb, line 43 def seek!() @io.seek(@offset) end