Skip to content

Commit e48f418

Browse files
committed
Minor clean ups
1 parent dfde65f commit e48f418

File tree

5 files changed

+29
-20
lines changed

5 files changed

+29
-20
lines changed

gems/aws-sdk-s3/lib/aws-sdk-s3/file_uploader.rb

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,23 +7,22 @@ module S3
77
# @api private
88
class FileUploader
99

10-
ONE_HUNDRED_MEGABYTES = 100 * 1024 * 1024
10+
# @api private
11+
DEFAULT_MULTIPART_THRESHOLD = 100 * 1024 * 1024
1112

1213
# @param [Hash] options
1314
# @option options [Client] :client
1415
# @option options [Integer] :multipart_threshold (104857600)
1516
def initialize(options = {})
1617
@options = options
1718
@client = options[:client] || Client.new
18-
@multipart_threshold = options[:multipart_threshold] ||
19-
ONE_HUNDRED_MEGABYTES
19+
@multipart_threshold = options[:multipart_threshold] || DEFAULT_MULTIPART_THRESHOLD
2020
end
2121

2222
# @return [Client]
2323
attr_reader :client
2424

25-
# @return [Integer] Files larger than or equal to this in bytes are uploaded
26-
# using a {MultipartFileUploader}.
25+
# @return [Integer] Files larger than or equal to this in bytes are uploaded using a {MultipartFileUploader}.
2726
attr_reader :multipart_threshold
2827

2928
# @param [String, Pathname, File, Tempfile] source The file to upload.

gems/aws-sdk-s3/lib/aws-sdk-s3/multipart_file_uploader.rb

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,26 +8,33 @@ module S3
88
# @api private
99
class MultipartFileUploader
1010

11+
# @api private
1112
MIN_PART_SIZE = 5 * 1024 * 1024 # 5MB
1213

14+
# @api private
1315
MAX_PARTS = 10_000
1416

17+
# @api private
1518
DEFAULT_THREAD_COUNT = 10
1619

20+
# @api private
1721
CREATE_OPTIONS = Set.new(Client.api.operation(:create_multipart_upload).input.shape.member_names)
1822

23+
# @api private
1924
COMPLETE_OPTIONS = Set.new(Client.api.operation(:complete_multipart_upload).input.shape.member_names)
2025

26+
# @api private
2127
UPLOAD_PART_OPTIONS = Set.new(Client.api.operation(:upload_part).input.shape.member_names)
2228

29+
# @api private
2330
CHECKSUM_KEYS = Set.new(
2431
Client.api.operation(:upload_part).input.shape.members.map do |n, s|
2532
n if s.location == 'header' && s.location_name.start_with?('x-amz-checksum-')
2633
end.compact
2734
)
2835

2936
# @option options [Client] :client
30-
# @option options [Integer] :thread_count (THREAD_COUNT)
37+
# @option options [Integer] :thread_count (DEFAULT_THREAD_COUNT)
3138
def initialize(options = {})
3239
@client = options[:client] || Client.new
3340
@thread_count = options[:thread_count] || DEFAULT_THREAD_COUNT

gems/aws-sdk-s3/lib/aws-sdk-s3/multipart_stream_uploader.rb

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,10 @@ module Aws
99
module S3
1010
# @api private
1111
class MultipartStreamUploader
12-
# api private
12+
# @api private
1313
DEFAULT_PART_SIZE = 5 * 1024 * 1024 # 5MB
1414

15+
# @api private
1516
DEFAULT_THREAD_COUNT = 10
1617

1718
# @api private
@@ -36,7 +37,7 @@ def initialize(options = {})
3637

3738
# @option options [required,String] :bucket
3839
# @option options [required,String] :key
39-
# @option options [Integer] :thread_count (10)
40+
# @option options [Integer] :thread_count (DEFAULT_THREAD_COUNT)
4041
# @return [Seahorse::Client::Response] - the CompleteMultipartUploadResponse
4142
def upload(options = {}, &block)
4243
Aws::Plugins::UserAgent.metric('S3_TRANSFER') do

gems/aws-sdk-s3/lib/aws-sdk-s3/transfer_manager.rb

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,11 @@ module S3
66
# capabilities with automatic multipart handling, progress tracking, and
77
# handling of large files. The following features are supported:
88
#
9-
# * upload a S3 object with multipart upload
9+
# * upload a file with multipart upload
10+
# * upload a stream with multipart upload
1011
# * download a S3 object with multipart download
1112
# * track transfer progress by using progress listener
13+
#
1214
class TransferManager
1315
# @param [Hash] options
1416
# @option options [S3::Client] :client (S3::Client.new)
@@ -25,12 +27,12 @@ def initialize(options = {})
2527
#
2628
# # small files (< 5MB) are downloaded in a single API call
2729
# tm = TransferManager.new
28-
# tm.download_file('/path/to/file', bucket: 'bucket-name', key: 'key-name')
30+
# tm.download_file('/path/to/file', bucket: 'bucket', key: 'key')
2931
#
3032
# Files larger than 5MB are downloaded using multipart method:
3133
#
3234
# # large files are split into parts and the parts are downloaded in parallel
33-
# tm.download_file('/path/to/large_file', bucket: 'bucket-name', key: 'key-name')
35+
# tm.download_file('/path/to/large_file', bucket: 'bucket', key: 'key')
3436
#
3537
# You can provide a callback to monitor progress of the download:
3638
#
@@ -41,7 +43,7 @@ def initialize(options = {})
4143
# puts "Part #{i + 1}: #{b} / #{part_sizes[i]}".join(' ') + "Total: #{100.0 * bytes.sum / file_size}%"
4244
# end
4345
# end
44-
# tm.download_file('/path/to/file', bucket: 'bucket-name', key: 'key-name', progress_callback: progress)
46+
# tm.download_file('/path/to/file', bucket: 'bucket', key: 'key', progress_callback: progress)
4547
#
4648
# @param [String] destination
4749
# Where to download the file to.
@@ -102,17 +104,17 @@ def download_file(destination, bucket:, key:, **options)
102104
#
103105
# # a small file are uploaded with PutObject API
104106
# tm = TransferManager.new
105-
# tm.upload_file('/path/to/small_file', bucket: 'bucket-name', key: 'key-name')
107+
# tm.upload_file('/path/to/small_file', bucket: 'bucket', key: 'key')
106108
#
107109
# Files larger than or equal to `:multipart_threshold` are uploaded using multipart upload APIs.
108110
#
109111
# # large files are automatically split into parts and the parts are uploaded in parallel
110-
# tm.upload_file('/path/to/large_file', bucket: 'bucket-name', key: 'key-name')
112+
# tm.upload_file('/path/to/large_file', bucket: 'bucket', key: 'key')
111113
#
112114
# The response of the S3 upload API is yielded if a block given.
113115
#
114116
# # API response will have etag value of the file
115-
# tm.upload_file('/path/to/file', bucket: 'bucket-name', key: 'key-name') do |response|
117+
# tm.upload_file('/path/to/file', bucket: 'bucket', key: 'key') do |response|
116118
# etag = response.etag
117119
# end
118120
#
@@ -124,7 +126,7 @@ def download_file(destination, bucket:, key:, **options)
124126
# puts "Part #{i + 1}: #{b} / #{totals[i]} " + "Total: #{100.0 * bytes.sum / totals.sum}%"
125127
# end
126128
# end
127-
# tm.upload_file('/path/to/file', bucket: 'bucket-name', key: 'key-name', progress_callback: progress)
129+
# tm.upload_file('/path/to/file', bucket: 'bucket', key: 'key', progress_callback: progress)
128130
#
129131
# @param [String, Pathname, File, Tempfile] source
130132
# A file on the local file system that will be uploaded. This can either be a `String` or `Pathname` to the
@@ -186,15 +188,15 @@ def upload_file(source, bucket:, key:, **options)
186188
#
187189
# @example Streaming chunks of data
188190
# tm = TransferManager.new
189-
# tm.upload_stream(bucket: 'example-bucket', key: 'example-key') do |write_stream|
191+
# tm.upload_stream(bucket: 'bucket', key: 'key') do |write_stream|
190192
# 10.times { write_stream << 'foo' }
191193
# end
192194
# @example Streaming chunks of data
193-
# tm.upload_stream(bucket: 'example-bucket', key: 'example-key') do |write_stream|
195+
# tm.upload_stream(bucket: 'bucket', key: 'key') do |write_stream|
194196
# IO.copy_stream(IO.popen('ls'), write_stream)
195197
# end
196198
# @example Streaming chunks of data
197-
# tm.upload_stream(bucket: 'example-bucket', key: 'example-key') do |write_stream|
199+
# tm.upload_stream(bucket: 'bucket', key: 'key') do |write_stream|
198200
# IO.copy_stream(STDIN, write_stream)
199201
# end
200202
#

gems/aws-sdk-s3/spec/file_uploader_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ module S3
2222
end
2323

2424
it 'sets a default multipart threshold when not given' do
25-
expect(subject.multipart_threshold).to be(FileUploader::ONE_HUNDRED_MEGABYTES)
25+
expect(subject.multipart_threshold).to be(FileUploader::DEFAULT_MULTIPART_THRESHOLD)
2626
end
2727

2828
it 'sets a custom multipart threshold' do

0 commit comments

Comments
 (0)