class Distillery::Archiver::LibArchive::InputStream
Public Class Methods
new(ar)
click to toggle source
# File lib/distillery/archiver/libarchive.rb, line 26 def initialize(ar) @read_block = ar.to_enum(:read_data, 16*1024) @buffer = StringIO.new end
Public Instance Methods
read(length=nil)
click to toggle source
# File lib/distillery/archiver/libarchive.rb, line 31 def read(length=nil) return '' if length&.zero? # Zero length request return nil if @buffer.nil? # End of stream # Read data data = @buffer.read(length) || "" while data.size < length do # We are short on data, that means buffer has been exhausted # request new data block from the archive block = @read_block.next # Break if we already read all the archive data if block.nil? || block.empty? @buffer = nil break end # Refill buffer from block @buffer.string = block # Continue reading data.concat(@buffer.read(length - data.size)) end data.empty? ? nil : data end