Class: Aws::S3::FileDownloader Private

Inherits:
Object
  • Object
show all
Defined in:
lib/aws-sdk-s3/file_downloader.rb

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

Defined Under Namespace

Classes: MultipartProgress, Part, PartList

Constant Summary collapse

MIN_CHUNK_SIZE =

This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.

5 * 1024 * 1024
MAX_PARTS =

This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.

10_000

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ FileDownloader

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns a new instance of FileDownloader.



15
16
17
# File 'lib/aws-sdk-s3/file_downloader.rb', line 15

def initialize(options = {})
  @client = options[:client] || Client.new
end

Instance Attribute Details

#clientClient (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns:



20
21
22
# File 'lib/aws-sdk-s3/file_downloader.rb', line 20

def client
  @client
end

Instance Method Details

#download(destination, options = {}) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/aws-sdk-s3/file_downloader.rb', line 22

def download(destination, options = {})
  valid_types = [String, Pathname, File, Tempfile]
  unless valid_types.include?(destination.class)
    raise ArgumentError, "Invalid destination, expected #{valid_types.join(', ')} but got: #{destination.class}"
  end

  @destination = destination
  @mode = options.delete(:mode) || 'auto'
  @thread_count = options.delete(:thread_count) || 10
  @chunk_size = options.delete(:chunk_size)
  @on_checksum_validated = options.delete(:on_checksum_validated)
  @progress_callback = options.delete(:progress_callback)
  @params = options
  validate!

  Aws::Plugins::UserAgent.metric('S3_TRANSFER') do
    case @mode
    when 'auto' then multipart_download
    when 'single_request' then single_request
    when 'get_range'
      raise ArgumentError, 'In get_range mode, :chunk_size must be provided' unless @chunk_size

      resp = @client.head_object(@params)
      multithreaded_get_by_ranges(resp.content_length, resp.etag)
    else
      raise ArgumentError, "Invalid mode #{@mode} provided, :mode should be single_request, get_range or auto"
    end
  end
  File.rename(@temp_path, @destination) if @temp_path
ensure
  File.delete(@temp_path) if @temp_path && File.exist?(@temp_path)
end