A utility class that turns a block (with 2 args) into an IO object that responds to read and eof. @private
# File lib/aws/s3/data_options.rb, line 146 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 168 def eof? @eof end
# File lib/aws/s3/data_options.rb, line 156 def read bytes = nil if bytes buffer = StringIO.new @write_block.call(buffer, bytes) buffer.rewind @eof = true if buffer.size < bytes buffer.size == 0 ? nil : buffer.read else read_all end end
# File lib/aws/s3/data_options.rb, line 174 def read_all buffer = StringIO.new buffer << read(1024 * 1024 * 5) until eof? buffer.rewind buffer.read end