Class: S3reamer::S3WriteStream
- Inherits:
-
Object
- Object
- S3reamer::S3WriteStream
- Defined in:
- lib/s3reamer/s3_write_stream.rb
Constant Summary collapse
- DEFAULT_OPTIONS =
{ chunk_size: 5 * 1024 * 1024 }
Instance Method Summary collapse
- #close ⇒ Object
- #flush ⇒ Object
-
#initialize(object, options = {}) ⇒ S3WriteStream
constructor
A new instance of S3WriteStream.
- #write(data) ⇒ Object
Constructor Details
#initialize(object, options = {}) ⇒ S3WriteStream
Returns a new instance of S3WriteStream.
7 8 9 10 11 12 |
# File 'lib/s3reamer/s3_write_stream.rb', line 7 def initialize(object, = {}) @buffer = String.new = DEFAULT_OPTIONS.merge() @multipart_upload = object.initiate_multipart_upload @closed = false end |
Instance Method Details
#close ⇒ Object
27 28 29 30 31 |
# File 'lib/s3reamer/s3_write_stream.rb', line 27 def close flush unless @buffer.empty? @multipart_upload.complete(compute_parts: true) @closed = true end |
#flush ⇒ Object
21 22 23 24 25 |
# File 'lib/s3reamer/s3_write_stream.rb', line 21 def flush part = @multipart_upload.part(@multipart_upload.parts.count + 1) part.upload(body: @buffer) @buffer.clear end |
#write(data) ⇒ Object
14 15 16 17 18 19 |
# File 'lib/s3reamer/s3_write_stream.rb', line 14 def write(data) raise RuntimeError.new("Illegal state: cannot write after close.") if @closed @buffer << data flush if @buffer.length >= [:chunk_size] end |