Class: DropboxApi::ChunkedUploader
- Inherits:
-
Object
- Object
- DropboxApi::ChunkedUploader
- Includes:
- OptionsValidator
- Defined in:
- lib/dropbox_api/chunked_uploader.rb
Instance Method Summary collapse
- #finish ⇒ Object
-
#initialize(client, path, i_stream, options = {}) ⇒ ChunkedUploader
constructor
A new instance of ChunkedUploader.
- #start ⇒ Object
- #upload ⇒ Object
Methods included from OptionsValidator
Constructor Details
#initialize(client, path, i_stream, options = {}) ⇒ ChunkedUploader
Returns a new instance of ChunkedUploader.
6 7 8 9 10 11 12 13 |
# File 'lib/dropbox_api/chunked_uploader.rb', line 6 def initialize(client, path, i_stream, = {}) @chunk_size = .delete(:chunk_size) || 4 * 1024 * 1024 # 4 MiB @client = client @i_stream = i_stream init_commit_info(path, ) end |
Instance Method Details
#finish ⇒ Object
32 33 34 |
# File 'lib/dropbox_api/chunked_uploader.rb', line 32 def finish @client.upload_session_finish @cursor, @commit_info end |
#start ⇒ Object
15 16 17 18 19 20 |
# File 'lib/dropbox_api/chunked_uploader.rb', line 15 def start chunk = @i_stream.read @chunk_size chunk = '' if chunk.nil? @cursor = @client.upload_session_start chunk end |
#upload ⇒ Object
22 23 24 25 26 27 28 29 30 |
# File 'lib/dropbox_api/chunked_uploader.rb', line 22 def upload loop do chunk = @i_stream.read @chunk_size break if chunk.nil? @client.upload_session_append_v2 @cursor, chunk break if chunk.size < @chunk_size end end |