Class: BucketStore::KeyStorage::KeyStreamer
- Inherits:
-
Object
- Object
- BucketStore::KeyStorage::KeyStreamer
- Defined in:
- lib/bucket_store/key_storage.rb
Overview
Defines a streaming interface for download and upload operations.
Note that individual adapters may require additional configuration for the correct behavior of the streaming interface.
Instance Attribute Summary collapse
-
#adapter_type ⇒ Object
readonly
Returns the value of attribute adapter_type.
-
#bucket ⇒ Object
readonly
Returns the value of attribute bucket.
-
#key ⇒ Object
readonly
Returns the value of attribute key.
Instance Method Summary collapse
-
#download(file:) ⇒ Object
Streams the content of the reference key into a file-like object.
-
#initialize(adapter:, adapter_type:, bucket:, key:) ⇒ KeyStreamer
constructor
A new instance of KeyStreamer.
-
#upload!(file:) ⇒ Object
Performs a streaming upload to the backing object store.
Constructor Details
#initialize(adapter:, adapter_type:, bucket:, key:) ⇒ KeyStreamer
Returns a new instance of KeyStreamer.
25 26 27 28 29 30 |
# File 'lib/bucket_store/key_storage.rb', line 25 def initialize(adapter:, adapter_type:, bucket:, key:) @adapter = adapter @adapter_type = adapter_type @bucket = bucket @key = key end |
Instance Attribute Details
#adapter_type ⇒ Object (readonly)
Returns the value of attribute adapter_type.
23 24 25 |
# File 'lib/bucket_store/key_storage.rb', line 23 def adapter_type @adapter_type end |
#bucket ⇒ Object (readonly)
Returns the value of attribute bucket.
23 24 25 |
# File 'lib/bucket_store/key_storage.rb', line 23 def bucket @bucket end |
#key ⇒ Object (readonly)
Returns the value of attribute key.
23 24 25 |
# File 'lib/bucket_store/key_storage.rb', line 23 def key @key end |
Instance Method Details
#download(file:) ⇒ Object
Streams the content of the reference key into a file-like object
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/bucket_store/key_storage.rb', line 41 def download(file:) BucketStore.logger.info(event: "key_storage.download_started") start = BucketStore::Timing.monotonic_now adapter.download( bucket: bucket, key: key, file: file, ) BucketStore.logger.info(event: "key_storage.download_finished", duration: BucketStore::Timing.monotonic_now - start) { bucket: bucket, key: key, file: file, } end |
#upload!(file:) ⇒ Object
Performs a streaming upload to the backing object store
69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 |
# File 'lib/bucket_store/key_storage.rb', line 69 def upload!(file:) raise ArgumentError, "Key cannot be empty" if key.empty? BucketStore.logger.info(event: "key_storage.upload_started", **log_context) start = BucketStore::Timing.monotonic_now adapter.upload!( bucket: bucket, key: key, file: file, ) BucketStore.logger.info(event: "key_storage.upload_finished", duration: BucketStore::Timing.monotonic_now - start, **log_context) "#{adapter_type}://#{bucket}/#{key}" end |