Class: OCI::ObjectStorage::Transfer::Multipart::Internal::SeekableNonFilePartIOWrapper
- Inherits:
-
Object
- Object
- OCI::ObjectStorage::Transfer::Multipart::Internal::SeekableNonFilePartIOWrapper
- Defined in:
- lib/oci/object_storage/transfer/multipart/internal/seekable_non_file_part_io_wrapper.rb
Overview
A class which wraps a seekable (but non-file) IO-like object (for example, a StringIO) so that we can extract a part of it to upload as an “upload part” of a multipart upload. This works by seeking to a given position in the IO-like object and then reading a certain number of bytes from that position onwards.
Reading a part of the IO-like object is synchronised so that only a single thread can access the IO at any one time. This prevents issues where we would do, for example, concurrent seeks and so potentially end up reading content we didn't intend to read.
Instance Attribute Summary collapse
-
#source ⇒ IO
readonly
The underlying IO-like object which we'll extract content from.
Instance Method Summary collapse
-
#initialize(source:) ⇒ SeekableNonFilePartIOWrapper
constructor
Creates a new SeekableNonFilePartIOWrapper.
-
#read(offset, part_size) ⇒ String
Reads a part/segment from the IO-like object by seeking to a given location and then reading a given number of bytes.
Constructor Details
#initialize(source:) ⇒ SeekableNonFilePartIOWrapper
Creates a new SeekableNonFilePartIOWrapper
24 25 26 27 28 29 |
# File 'lib/oci/object_storage/transfer/multipart/internal/seekable_non_file_part_io_wrapper.rb', line 24 def initialize(source:) raise 'The provided source is not seekable' unless source.respond_to?(:seek) @source = source @lock = Mutex.new end |
Instance Attribute Details
#source ⇒ IO (readonly)
The underlying IO-like object which we'll extract content from
20 21 22 |
# File 'lib/oci/object_storage/transfer/multipart/internal/seekable_non_file_part_io_wrapper.rb', line 20 def source @source end |
Instance Method Details
#read(offset, part_size) ⇒ String
Reads a part/segment from the IO-like object by seeking to a given location and then reading a given number of bytes. This is synchronised so that only a single thread can perform this operation at any one time.
39 40 41 42 43 44 |
# File 'lib/oci/object_storage/transfer/multipart/internal/seekable_non_file_part_io_wrapper.rb', line 39 def read(offset, part_size) @lock.synchronize do @source.seek(offset) @source.read(part_size) end end |