Class: Aliyun::OSS::Multipart::Download
- Inherits:
-
Transaction
- Object
- Struct::Base
- Transaction
- Aliyun::OSS::Multipart::Download
- Defined in:
- lib/aliyun/oss/download.rb
Overview
A multipart download transaction
Constant Summary collapse
- PART_SIZE =
10 * 1024 * 1024
- READ_SIZE =
16 * 1024
Constants included from Logging
Instance Method Summary collapse
-
#checkpoint ⇒ Object
Checkpoint structures:.
-
#initialize(protocol, opts) ⇒ Download
constructor
A new instance of Download.
-
#run ⇒ Object
Run the download transaction, which includes 3 stages: * 1a.
Methods included from Logging
#logger, set_log_file, set_log_level
Methods inherited from Struct::Base
Methods included from Struct::Base::AttrHelper
Constructor Details
#initialize(protocol, opts) ⇒ Download
Returns a new instance of Download.
13 14 15 16 17 18 19 20 21 22 |
# File 'lib/aliyun/oss/download.rb', line 13 def initialize(protocol, opts) args = opts.dup @protocol = protocol @progress = args.delete(:progress) @file = args.delete(:file) @checkpoint_file = args.delete(:cpt_file) @object_meta = {} @parts = [] super(args) end |
Instance Method Details
#checkpoint ⇒ Object
Checkpoint structures:
64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 |
# File 'lib/aliyun/oss/download.rb', line 64 def checkpoint logger.debug("Begin make checkpoint, "\ "disable_cpt: #{[:disable_cpt]}") ensure_object_not_changed states = { :id => id, :file => @file, :object_meta => @object_meta, :parts => @parts } # report progress if @progress done = @parts.count { |p| p[:done] } @progress.call(done.to_f / @parts.size) if done > 0 end write_checkpoint(states, @checkpoint_file) unless [:disable_cpt] logger.debug("Done make checkpoint, states: #{states}") end |
#run ⇒ Object
Run the download transaction, which includes 3 stages:
-
1a. initiate(new downlaod) and divide parts
-
1b. rebuild states(resumed download)
-
download each unfinished part
-
-
combine the downloaded parts into the final file
-
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/aliyun/oss/download.rb', line 29 def run logger.info("Begin download, file: #{@file}, checkpoint file: "\ "#{@checkpoint_file}") # Rebuild transaction states from checkpoint file # Or initiate new transaction states rebuild # Divide the target object into parts to download by ranges divide_parts if @parts.empty? # Download each part(object range) @parts.reject { |p| p[:done]}.each { |p| download_part(p) } # Combine the parts into the final file commit logger.info("Done download, file: #{@file}") end |