Class: ActiveStorageEncryption::ResumableGCSUpload::RangedPutIO
- Inherits:
-
Object
- Object
- ActiveStorageEncryption::ResumableGCSUpload::RangedPutIO
- Extended by:
- Forwardable
- Defined in:
- lib/active_storage_encryption/resumable_gcs_upload.rb
Overview
Largely inspired by gist.github.com/frankyn/9a5344d1b19ed50ebbf9f15f0ff92032 Acts like a writable object that you send data into. The object will split the data you send into chunks and send it to GCP cloud storage, you do not need to indicate the size of the output in advance. You do need to close the object to deliver the last chunk
Constant Summary collapse
- CHUNK_SIZE_UNIT =
The chunks have to be sized in multiples of 256 kibibytes or 262,144 bytes
256 * 1024
Instance Method Summary collapse
-
#initialize(put_url, chunk_size:, content_type: "binary/octet-stream") ⇒ RangedPutIO
constructor
A new instance of RangedPutIO.
Constructor Details
#initialize(put_url, chunk_size:, content_type: "binary/octet-stream") ⇒ RangedPutIO
Returns a new instance of RangedPutIO.
90 91 92 93 94 95 96 97 98 |
# File 'lib/active_storage_encryption/resumable_gcs_upload.rb', line 90 def initialize(put_url, chunk_size:, content_type: "binary/octet-stream") raise ArgumentError, "chunk_size of #{chunk_size} is not a multiple of #{CHUNK_SIZE_UNIT}" unless (chunk_size % CHUNK_SIZE_UNIT).zero? @put_uri = URI(put_url) @last_byte = 0 @total_bytes = 0 @content_type = content_type @chunker = ByteChunker.new(chunk_size: chunk_size) { |bytes, is_last| upload_chunk(bytes, is_last) } end |