Class: Etna::Clients::Metis::MetisUploadWorkflow::Upload
- Inherits:
-
Struct
- Object
- Struct
- Etna::Clients::Metis::MetisUploadWorkflow::Upload
- Defined in:
- lib/etna/clients/metis/workflows/metis_upload_workflow.rb
Constant Summary collapse
- INITIAL_BLOB_SIZE =
2 ** 10
- MAX_BLOB_SIZE =
2 ** 22
- ZERO_HASH =
'd41d8cd98f00b204e9800998ecf8427e'
Instance Method Summary collapse
- #advance_position! ⇒ Object
- #complete? ⇒ Boolean
- #file_size ⇒ Object
-
#initialize(**args) ⇒ Upload
constructor
A new instance of Upload.
- #next_blob_bytes ⇒ Object
- #next_blob_hash ⇒ Object
- #resume_from!(upload_response) ⇒ Object
Constructor Details
#initialize(**args) ⇒ Upload
Returns a new instance of Upload.
98 99 100 101 102 |
# File 'lib/etna/clients/metis/workflows/metis_upload_workflow.rb', line 98 def initialize(**args) super self.next_blob_size = [file_size, INITIAL_BLOB_SIZE].min self.current_byte_position = 0 end |
Instance Method Details
#advance_position! ⇒ Object
108 109 110 111 112 113 114 115 |
# File 'lib/etna/clients/metis/workflows/metis_upload_workflow.rb', line 108 def advance_position! self.current_byte_position = self.current_byte_position + self.next_blob_size self.next_blob_size = [ MAX_BLOB_SIZE, # in fact we should stop when we hit the end of the file file_size - current_byte_position ].min end |
#complete? ⇒ Boolean
117 118 119 |
# File 'lib/etna/clients/metis/workflows/metis_upload_workflow.rb', line 117 def complete? current_byte_position >= file_size end |
#file_size ⇒ Object
104 105 106 |
# File 'lib/etna/clients/metis/workflows/metis_upload_workflow.rb', line 104 def file_size ::File.size(source_file) end |
#next_blob_bytes ⇒ Object
125 126 127 |
# File 'lib/etna/clients/metis/workflows/metis_upload_workflow.rb', line 125 def next_blob_bytes IO.binread(source_file, next_blob_size, current_byte_position) end |
#next_blob_hash ⇒ Object
121 122 123 |
# File 'lib/etna/clients/metis/workflows/metis_upload_workflow.rb', line 121 def next_blob_hash Digest::MD5.hexdigest(next_blob_bytes) end |
#resume_from!(upload_response) ⇒ Object
129 130 131 132 |
# File 'lib/etna/clients/metis/workflows/metis_upload_workflow.rb', line 129 def resume_from!(upload_response) self.current_byte_position = upload_response.current_byte_position self.next_blob_size = upload_response.next_blob_size end |