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.

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
THREAD_COUNT =

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

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
# File 'lib/aws-sdk-s3/file_downloader.rb', line 22

def download(destination, options = {})
  @path = destination
  @mode = options[:mode] || "auto"
  @thread_count = options[:thread_count] || THREAD_COUNT
  @chunk_size = options[:chunk_size]
  @bucket = options[:bucket]
  @key = options[:key]

  case @mode
  when "auto" then multipart_download
  when "single_request" then single_request
  when "get_range"
    if @chunk_size
      resp = @client.head_object(bucket: @bucket, key: @key)
      multithreaded_get_by_ranges(construct_chunks(resp.content_length))
    else
      msg = "In :get_range mode, :chunk_size must be provided"
      raise ArgumentError, msg
    end
  else
    msg = "Invalid mode #{@mode} provided, "\
      "mode should be :single_request, :get_range or :auto"
    raise ArgumentError, msg
  end
end