Class: OCI::ObjectStorage::Transfer::Multipart::Internal::StdinPartIOWrapper
- Inherits:
-
Object
- Object
- OCI::ObjectStorage::Transfer::Multipart::Internal::StdinPartIOWrapper
- Defined in:
- lib/oci/object_storage/transfer/multipart/internal/stdin_part_io_wrapper.rb
Overview
A class which wraps standard input ($stdin) so that, for example, piped input can participate in multipart uploads. Standard input is not seekable so we need a special class to handle it rather than using SeekableNonFilePartIOWrapper.
This class can also vend data for each part to upload as part of a multipart upload. However, since we may not know the full size of $stdin beforehand, in addition to vending data this wrapper will also vend the part number to assign to the uploaded part.
Reading data out of stdin is synchronised so that only a single thread can read at any one time. This prevents issues where we could write the same part multiple times or write inconsistent data.
Instance Attribute Summary collapse
-
#source ⇒ IO
readonly
A reference to $stdin.
Instance Method Summary collapse
-
#initialize(source:) ⇒ StdinPartIOWrapper
constructor
Creates a new StdinPartIOWrapper.
-
#read(part_size) ⇒ Hash
Reads bytes from $stdin.
Constructor Details
#initialize(source:) ⇒ StdinPartIOWrapper
Creates a new StdinPartIOWrapper
27 28 29 30 31 |
# File 'lib/oci/object_storage/transfer/multipart/internal/stdin_part_io_wrapper.rb', line 27 def initialize(source:) @source = source @lock = Mutex.new @part_number = 0 end |
Instance Attribute Details
#source ⇒ IO (readonly)
A reference to $stdin
22 23 24 |
# File 'lib/oci/object_storage/transfer/multipart/internal/stdin_part_io_wrapper.rb', line 22 def source @source end |
Instance Method Details
#read(part_size) ⇒ Hash
Reads bytes from $stdin. This is synchronised so that only a single thread can perform this operation at any one time.
and the :part_number key will contain the part number we will assign to the part when we upload it as part of a multipart upload. If there is no more data from $stdin then this method will return nil.
41 42 43 44 45 46 47 48 49 |
# File 'lib/oci/object_storage/transfer/multipart/internal/stdin_part_io_wrapper.rb', line 41 def read(part_size) @lock.synchronize do read_content = @source.read(part_size) if read_content @part_number += 1 { content: read_content, part_number: @part_number } end end end |