A utility class that turns a block (with 2 args) into an IO object that responds to read and eof. @api private
# File lib/aws/s3/data_options.rb, line 147 def initialize write_block unless write_block.arity == 2 msg = "a write block must accept 2 yield params: a buffer and " msg << "a number of bytes to write" raise ArgumentError, msg end @write_block = write_block @eof = false end
# File lib/aws/s3/data_options.rb, line 166 def eof? @eof end
# File lib/aws/s3/data_options.rb, line 157 def read bytes = nil, output_buffer = nil data = if bytes (@eof) ? nil : read_chunk(bytes) else (@eof) ? "" : read_all end output_buffer ? output_buffer.replace(data || '') : data end
# File lib/aws/s3/data_options.rb, line 180 def read_all buffer = StringIO.new buffer << read_chunk(1024 * 1024 * 5) until @eof buffer.rewind buffer.read end
# File lib/aws/s3/data_options.rb, line 172 def read_chunk bytes buffer = StringIO.new @write_block.call(buffer, bytes) buffer.rewind @eof = true if buffer.size < bytes buffer.read end