Class: Aws::S3::FileDownloader Private
- Inherits:
-
Object
- Object
- Aws::S3::FileDownloader
- 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
- #client ⇒ Client readonly private
Instance Method Summary collapse
- #download(destination, options = {}) ⇒ Object private
-
#initialize(options = {}) ⇒ FileDownloader
constructor
private
A new instance of FileDownloader.
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( = {}) @client = [:client] || Client.new end |
Instance Attribute Details
#client ⇒ Client (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.
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, = {}) 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 = .delete(:mode) || 'auto' @thread_count = .delete(:thread_count) || 10 @chunk_size = .delete(:chunk_size) @on_checksum_validated = .delete(:on_checksum_validated) @progress_callback = .delete(:progress_callback) @params = 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 |