Method: Aliyun::OSS::Multipart::Download#run

Defined in:
lib/aliyun/oss/download.rb

#runObject

Run the download transaction, which includes 3 stages:

  • 1a. initiate(new downlaod) and divide parts

  • 1b. rebuild states(resumed download)

    1. download each unfinished part

    1. combine the downloaded parts into the final file



38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
# File 'lib/aliyun/oss/download.rb', line 38

def run
  logger.info("Begin download, file: #{@file}, "\
              "checkpoint file: #{@cpt_file}, "\
              "threads: #{@num_threads}")

  # 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)
  @todo_parts = @parts.reject { |p| p[:done] }

  (1..@num_threads).map {
    Thread.new {
      loop {
        p = sync_get_todo_part
        break unless p
        download_part(p)
      }
    }
  }.map(&:join)

  # Combine the parts into the final file
  commit

  logger.info("Done download, file: #{@file}")
end