Class: Etna::Clients::Metis::MetisUploadWorkflow::Upload
- Inherits:
-
Object
- Object
- Etna::Clients::Metis::MetisUploadWorkflow::Upload
- Defined in:
- lib/etna/clients/metis/workflows/metis_upload_workflow.rb
Direct Known Subclasses
Constant Summary collapse
- INITIAL_BLOB_SIZE =
2 ** 10
- MAX_BLOB_SIZE =
2 ** 22
- ZERO_HASH =
'd41d8cd98f00b204e9800998ecf8427e'
Instance Attribute Summary collapse
-
#current_byte_position ⇒ Object
Returns the value of attribute current_byte_position.
-
#next_blob_size ⇒ Object
Returns the value of attribute next_blob_size.
-
#source_file ⇒ Object
Returns the value of attribute source_file.
Instance Method Summary collapse
- #advance_position! ⇒ Object
- #complete? ⇒ Boolean
- #file_size ⇒ Object
-
#initialize(source_file: nil, next_blob_size: nil, current_byte_position: nil) ⇒ Upload
constructor
A new instance of Upload.
- #next_blob_bytes ⇒ Object
- #next_blob_hash ⇒ Object
- #resume_from!(upload_response) ⇒ Object
Constructor Details
#initialize(source_file: nil, next_blob_size: nil, current_byte_position: nil) ⇒ Upload
Returns a new instance of Upload.
111 112 113 114 115 |
# File 'lib/etna/clients/metis/workflows/metis_upload_workflow.rb', line 111 def initialize(source_file: nil, next_blob_size: nil, current_byte_position: nil) self.source_file = source_file self.next_blob_size = [file_size, INITIAL_BLOB_SIZE].min self.current_byte_position = 0 end |
Instance Attribute Details
#current_byte_position ⇒ Object
Returns the value of attribute current_byte_position.
109 110 111 |
# File 'lib/etna/clients/metis/workflows/metis_upload_workflow.rb', line 109 def current_byte_position @current_byte_position end |
#next_blob_size ⇒ Object
Returns the value of attribute next_blob_size.
109 110 111 |
# File 'lib/etna/clients/metis/workflows/metis_upload_workflow.rb', line 109 def next_blob_size @next_blob_size end |
#source_file ⇒ Object
Returns the value of attribute source_file.
109 110 111 |
# File 'lib/etna/clients/metis/workflows/metis_upload_workflow.rb', line 109 def source_file @source_file end |
Instance Method Details
#advance_position! ⇒ Object
121 122 123 124 125 126 127 128 |
# File 'lib/etna/clients/metis/workflows/metis_upload_workflow.rb', line 121 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
130 131 132 |
# File 'lib/etna/clients/metis/workflows/metis_upload_workflow.rb', line 130 def complete? current_byte_position >= file_size end |
#file_size ⇒ Object
117 118 119 |
# File 'lib/etna/clients/metis/workflows/metis_upload_workflow.rb', line 117 def file_size ::File.size(source_file) end |
#next_blob_bytes ⇒ Object
145 146 147 |
# File 'lib/etna/clients/metis/workflows/metis_upload_workflow.rb', line 145 def next_blob_bytes IO.binread(source_file, next_blob_size, current_byte_position) end |
#next_blob_hash ⇒ Object
134 135 136 137 138 139 140 141 142 143 |
# File 'lib/etna/clients/metis/workflows/metis_upload_workflow.rb', line 134 def next_blob_hash bytes = next_blob_bytes if bytes.empty? return ZERO_HASH end $digest_mutx.synchronize do return Digest::MD5.hexdigest(bytes) end end |
#resume_from!(upload_response) ⇒ Object
149 150 151 152 |
# File 'lib/etna/clients/metis/workflows/metis_upload_workflow.rb', line 149 def resume_from!(upload_response) self.current_byte_position = upload_response.current_byte_position self.next_blob_size = upload_response.next_blob_size end |