aws-sdk-s3 1.196.1 → 1.213.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (67) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +116 -0
  3. data/VERSION +1 -1
  4. data/lib/aws-sdk-s3/bucket.rb +17 -17
  5. data/lib/aws-sdk-s3/bucket_acl.rb +1 -1
  6. data/lib/aws-sdk-s3/bucket_versioning.rb +33 -0
  7. data/lib/aws-sdk-s3/client.rb +1271 -453
  8. data/lib/aws-sdk-s3/client_api.rb +115 -0
  9. data/lib/aws-sdk-s3/customizations/object.rb +39 -24
  10. data/lib/aws-sdk-s3/customizations.rb +3 -1
  11. data/lib/aws-sdk-s3/default_executor.rb +103 -0
  12. data/lib/aws-sdk-s3/encryption/client.rb +2 -2
  13. data/lib/aws-sdk-s3/encryption/default_cipher_provider.rb +2 -0
  14. data/lib/aws-sdk-s3/encryption/encrypt_handler.rb +2 -0
  15. data/lib/aws-sdk-s3/encryption/kms_cipher_provider.rb +2 -0
  16. data/lib/aws-sdk-s3/encryptionV2/client.rb +98 -23
  17. data/lib/aws-sdk-s3/encryptionV2/decrypt_handler.rb +7 -162
  18. data/lib/aws-sdk-s3/encryptionV2/decryption.rb +205 -0
  19. data/lib/aws-sdk-s3/encryptionV2/default_cipher_provider.rb +17 -0
  20. data/lib/aws-sdk-s3/encryptionV2/encrypt_handler.rb +2 -0
  21. data/lib/aws-sdk-s3/encryptionV2/io_encrypter.rb +2 -0
  22. data/lib/aws-sdk-s3/encryptionV2/kms_cipher_provider.rb +8 -0
  23. data/lib/aws-sdk-s3/encryptionV2/utils.rb +5 -0
  24. data/lib/aws-sdk-s3/encryptionV3/client.rb +885 -0
  25. data/lib/aws-sdk-s3/encryptionV3/decrypt_handler.rb +98 -0
  26. data/lib/aws-sdk-s3/encryptionV3/decryption.rb +244 -0
  27. data/lib/aws-sdk-s3/encryptionV3/default_cipher_provider.rb +159 -0
  28. data/lib/aws-sdk-s3/encryptionV3/default_key_provider.rb +35 -0
  29. data/lib/aws-sdk-s3/encryptionV3/encrypt_handler.rb +98 -0
  30. data/lib/aws-sdk-s3/encryptionV3/errors.rb +47 -0
  31. data/lib/aws-sdk-s3/encryptionV3/io_auth_decrypter.rb +60 -0
  32. data/lib/aws-sdk-s3/encryptionV3/io_decrypter.rb +35 -0
  33. data/lib/aws-sdk-s3/encryptionV3/io_encrypter.rb +84 -0
  34. data/lib/aws-sdk-s3/encryptionV3/key_provider.rb +28 -0
  35. data/lib/aws-sdk-s3/encryptionV3/kms_cipher_provider.rb +159 -0
  36. data/lib/aws-sdk-s3/encryptionV3/materials.rb +58 -0
  37. data/lib/aws-sdk-s3/encryptionV3/utils.rb +321 -0
  38. data/lib/aws-sdk-s3/encryption_v2.rb +1 -0
  39. data/lib/aws-sdk-s3/encryption_v3.rb +24 -0
  40. data/lib/aws-sdk-s3/endpoint_parameters.rb +17 -17
  41. data/lib/aws-sdk-s3/endpoint_provider.rb +241 -68
  42. data/lib/aws-sdk-s3/endpoints.rb +39 -0
  43. data/lib/aws-sdk-s3/errors.rb +11 -0
  44. data/lib/aws-sdk-s3/file_downloader.rb +192 -104
  45. data/lib/aws-sdk-s3/file_uploader.rb +17 -13
  46. data/lib/aws-sdk-s3/multipart_file_uploader.rb +82 -69
  47. data/lib/aws-sdk-s3/multipart_stream_uploader.rb +96 -107
  48. data/lib/aws-sdk-s3/multipart_upload.rb +12 -12
  49. data/lib/aws-sdk-s3/multipart_upload_part.rb +8 -8
  50. data/lib/aws-sdk-s3/object.rb +88 -59
  51. data/lib/aws-sdk-s3/object_acl.rb +5 -5
  52. data/lib/aws-sdk-s3/object_summary.rb +70 -41
  53. data/lib/aws-sdk-s3/object_version.rb +23 -25
  54. data/lib/aws-sdk-s3/plugins/checksum_algorithm.rb +18 -5
  55. data/lib/aws-sdk-s3/plugins/endpoints.rb +1 -1
  56. data/lib/aws-sdk-s3/plugins/http_200_errors.rb +58 -34
  57. data/lib/aws-sdk-s3/transfer_manager.rb +321 -0
  58. data/lib/aws-sdk-s3/types.rb +687 -330
  59. data/lib/aws-sdk-s3.rb +1 -1
  60. data/sig/bucket.rbs +1 -1
  61. data/sig/client.rbs +62 -12
  62. data/sig/errors.rbs +2 -0
  63. data/sig/multipart_upload.rbs +1 -1
  64. data/sig/object.rbs +7 -5
  65. data/sig/object_summary.rbs +7 -5
  66. data/sig/types.rbs +84 -14
  67. metadata +21 -3
@@ -3,15 +3,28 @@
3
3
  module Aws
4
4
  module S3
5
5
  module Plugins
6
-
7
6
  # A handful of Amazon S3 operations will respond with a 200 status
8
7
  # code but will send an error in the response body. This plugin
9
8
  # injects a handler that will parse 200 response bodies for potential
10
9
  # errors, allowing them to be retried.
11
10
  # @api private
12
11
  class Http200Errors < Seahorse::Client::Plugin
13
-
14
12
  class Handler < Seahorse::Client::Handler
13
+ # A regular expression to match error codes in the response body
14
+ CODE_PATTERN = %r{<Code>(.+?)</Code>}.freeze
15
+ private_constant :CODE_PATTERN
16
+
17
+ # A list of encodings we force into UTF-8
18
+ ENCODINGS_TO_FIX = [Encoding::US_ASCII, Encoding::ASCII_8BIT].freeze
19
+ private_constant :ENCODINGS_TO_FIX
20
+
21
+ # A regular expression to match detect errors in the response body
22
+ ERROR_PATTERN = /<\?xml\s[^>]*\?>\s*<Error>/.freeze
23
+ private_constant :ERROR_PATTERN
24
+
25
+ # A regular expression to match an error message in the response body
26
+ MESSAGE_PATTERN = %r{<Message>(.+?)</Message>}.freeze
27
+ private_constant :MESSAGE_PATTERN
15
28
 
16
29
  def call(context)
17
30
  @handler.call(context).on(200) do |response|
@@ -28,29 +41,37 @@ module Aws
28
41
 
29
42
  private
30
43
 
31
- # Streaming outputs are not subject to 200 errors.
32
- def streaming_output?(output)
33
- if (payload = output[:payload_member])
34
- # checking ref and shape
35
- payload['streaming'] || payload.shape['streaming'] ||
36
- payload.eventstream
37
- else
38
- false
44
+ def build_error(context, code, message)
45
+ S3::Errors.error_class(code).new(context, message)
46
+ end
47
+
48
+ def check_for_error(context)
49
+ xml = normalize_encoding(context.http_response.body_contents)
50
+
51
+ if xml.match?(ERROR_PATTERN)
52
+ error_code = xml.match(CODE_PATTERN)[1]
53
+ error_message = xml.match(MESSAGE_PATTERN)[1]
54
+ build_error(context, error_code, error_message)
55
+ elsif incomplete_xml_body?(xml, context.operation.output)
56
+ Seahorse::Client::NetworkingError.new(
57
+ build_error(context, 'InternalError', 'Empty or incomplete response body')
58
+ )
39
59
  end
40
60
  end
41
61
 
62
+ # Must have a member in the body and have the start of an XML Tag.
63
+ # Other incomplete xml bodies will result in an XML ParsingError.
64
+ def incomplete_xml_body?(xml, output)
65
+ members_in_body?(output) && !xml.match(/<\w/)
66
+ end
67
+
42
68
  # Checks if the output shape is a structure shape and has members that
43
69
  # are in the body for the case of a payload and a normal structure. A
44
70
  # non-structure shape will not have members in the body. In the case
45
71
  # of a string or blob, the body contents would have been checked first
46
72
  # before this method is called in incomplete_xml_body?.
47
73
  def members_in_body?(output)
48
- shape =
49
- if output[:payload_member]
50
- output[:payload_member].shape
51
- else
52
- output.shape
53
- end
74
+ shape = resolve_shape(output)
54
75
 
55
76
  if structure_shape?(shape)
56
77
  shape.members.any? { |_, k| k.location.nil? }
@@ -59,30 +80,33 @@ module Aws
59
80
  end
60
81
  end
61
82
 
62
- def structure_shape?(shape)
63
- shape.is_a?(Seahorse::Model::Shapes::StructureShape)
83
+ # Fixes encoding issues when S3 returns UTF-8 content with missing charset in Content-Type header or omits
84
+ # Content-Type header entirely. Net::HTTP defaults to US-ASCII or ASCII-8BIT when charset is unspecified.
85
+ def normalize_encoding(xml)
86
+ return xml unless xml.is_a?(String) && ENCODINGS_TO_FIX.include?(xml.encoding)
87
+
88
+ xml.force_encoding('UTF-8')
64
89
  end
65
90
 
66
- # Must have a member in the body and have the start of an XML Tag.
67
- # Other incomplete xml bodies will result in an XML ParsingError.
68
- def incomplete_xml_body?(xml, output)
69
- members_in_body?(output) && !xml.match(/<\w/)
91
+ def resolve_shape(output)
92
+ return output.shape unless output[:payload_member]
93
+
94
+ output[:payload_member].shape
70
95
  end
71
96
 
72
- def check_for_error(context)
73
- xml = context.http_response.body_contents
74
- if xml.match(/<\?xml\s[^>]*\?>\s*<Error>/)
75
- error_code = xml.match(%r{<Code>(.+?)</Code>})[1]
76
- error_message = xml.match(%r{<Message>(.+?)</Message>})[1]
77
- S3::Errors.error_class(error_code).new(context, error_message)
78
- elsif incomplete_xml_body?(xml, context.operation.output)
79
- Seahorse::Client::NetworkingError.new(
80
- S3::Errors
81
- .error_class('InternalError')
82
- .new(context, 'Empty or incomplete response body')
83
- )
97
+ # Streaming outputs are not subject to 200 errors.
98
+ def streaming_output?(output)
99
+ if (payload = output[:payload_member])
100
+ # checking ref and shape
101
+ payload['streaming'] || payload.shape['streaming'] || payload.eventstream
102
+ else
103
+ false
84
104
  end
85
105
  end
106
+
107
+ def structure_shape?(shape)
108
+ shape.is_a?(Seahorse::Model::Shapes::StructureShape)
109
+ end
86
110
  end
87
111
 
88
112
  handler(Handler, step: :sign)
@@ -0,0 +1,321 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Aws
4
+ module S3
5
+ # A high-level S3 transfer utility that provides enhanced upload and download capabilities with automatic
6
+ # multipart handling, progress tracking, and handling of large files. The following features are supported:
7
+ #
8
+ # * upload a file with multipart upload
9
+ # * upload a stream with multipart upload
10
+ # * download a S3 object with multipart download
11
+ # * track transfer progress by using progress listener
12
+ #
13
+ # ## Executor Management
14
+ # TransferManager uses executors to handle concurrent operations during multipart transfers. You can control
15
+ # concurrency behavior by providing a custom executor or relying on the default executor management.
16
+ #
17
+ # ### Default Behavior
18
+ # When no `:executor` is provided, TransferManager creates a new DefaultExecutor for each individual
19
+ # operation (`download_file`, `upload_file`, etc.) and automatically shuts it down when that operation completes.
20
+ # Each operation gets its own isolated thread pool with the specified `:thread_count` (default 10 threads).
21
+ #
22
+ # ### Custom Executor
23
+ # You can provide your own executor (e.g., `Concurrent::ThreadPoolExecutor`) for fine-grained control over thread
24
+ # pools and resource management. When using a custom executor, you are responsible for shutting it down
25
+ # when finished. The executor may be reused across multiple TransferManager operations.
26
+ #
27
+ # Custom executors must implement the same interface as DefaultExecutor.
28
+ #
29
+ # **Required methods:**
30
+ #
31
+ # * `post(*args, &block)` - Execute a task with given arguments and block
32
+ # * `kill` - Immediately terminate all running tasks
33
+ #
34
+ # **Optional methods:**
35
+ #
36
+ # * `shutdown(timeout = nil)` - Gracefully shutdown the executor with optional timeout
37
+ #
38
+ # @example Using default executor (automatic creation and shutdown)
39
+ # tm = TransferManager.new # No executor provided
40
+ # # DefaultExecutor created, used, and shutdown automatically
41
+ # tm.download_file('/path/to/file', bucket: 'bucket', key: 'key')
42
+ #
43
+ # @example Using custom executor (manual shutdown required)
44
+ # require 'concurrent-ruby'
45
+ #
46
+ # executor = Concurrent::ThreadPoolExecutor.new(max_threads: 5)
47
+ # tm = TransferManager.new(executor: executor)
48
+ # tm.download_file('/path/to/file1', bucket: 'bucket', key: 'key1')
49
+ # executor.shutdown # You must shutdown custom executors
50
+ #
51
+ class TransferManager
52
+
53
+ # @param [Hash] options
54
+ # @option options [S3::Client] :client (S3::Client.new)
55
+ # The S3 client to use for {TransferManager} operations. If not provided, a new default client
56
+ # will be created automatically.
57
+ # @option options [Object] :executor
58
+ # The executor to use for multipart operations. Must implement the same interface as {DefaultExecutor}.
59
+ # If not provided, a new {DefaultExecutor} will be created automatically for each operation and
60
+ # shutdown after completion. When provided a custom executor, it will be reused across operations, and
61
+ # you are responsible for shutting it down when finished.
62
+ def initialize(options = {})
63
+ @client = options[:client] || Client.new
64
+ @executor = options[:executor]
65
+ end
66
+
67
+ # @return [S3::Client]
68
+ attr_reader :client
69
+
70
+ # @return [Object]
71
+ attr_reader :executor
72
+
73
+ # Downloads a file in S3 to a path on disk.
74
+ #
75
+ # # small files (< 5MB) are downloaded in a single API call
76
+ # tm = TransferManager.new
77
+ # tm.download_file('/path/to/file', bucket: 'bucket', key: 'key')
78
+ #
79
+ # Files larger than 5MB are downloaded using multipart method:
80
+ #
81
+ # # large files are split into parts and the parts are downloaded in parallel
82
+ # tm.download_file('/path/to/large_file', bucket: 'bucket', key: 'key')
83
+ #
84
+ # You can provide a callback to monitor progress of the download:
85
+ #
86
+ # # bytes and part_sizes are each an array with 1 entry per part
87
+ # # part_sizes may not be known until the first bytes are retrieved
88
+ # progress = proc do |bytes, part_sizes, file_size|
89
+ # bytes.map.with_index do |b, i|
90
+ # puts "Part #{i + 1}: #{b} / #{part_sizes[i]}".join(' ') + "Total: #{100.0 * bytes.sum / file_size}%"
91
+ # end
92
+ # end
93
+ # tm.download_file('/path/to/file', bucket: 'bucket', key: 'key', progress_callback: progress)
94
+ #
95
+ # @param [String, Pathname, File, Tempfile] destination
96
+ # Where to download the file to. This can either be a String or Pathname to the file, an open File object,
97
+ # or an open Tempfile object. If you pass an open File or Tempfile object, then you are responsible for
98
+ # closing it after the download completes. Download behavior varies by destination type:
99
+ #
100
+ # * **String/Pathname paths**: Downloads to a temporary file first, then atomically moves to the final
101
+ # destination. This prevents corruption of any existing file if the download fails.
102
+ # * **File/Tempfile objects**: Downloads directly to the file object without using temporary files.
103
+ # You are responsible for managing the file object's state and closing it after the download completes.
104
+ # If the download fails, the file object may contain partial data.
105
+ #
106
+ # @param [String] bucket
107
+ # The name of the S3 bucket to upload to.
108
+ #
109
+ # @param [String] key
110
+ # The object key name in S3 bucket.
111
+ #
112
+ # @param [Hash] options
113
+ # Additional options for {Client#get_object} and #{Client#head_object} may be provided.
114
+ #
115
+ # @option options [String] :mode ("auto") `"auto"`, `"single_request"` or `"get_range"`
116
+ #
117
+ # * `"auto"` mode is enabled by default, which performs `multipart_download`
118
+ # * `"single_request`" mode forces only 1 GET request is made in download
119
+ # * `"get_range"` mode requires `:chunk_size` parameter to configured in customizing each range size
120
+ #
121
+ # @option options [Integer] :chunk_size required in `"get_range"` mode.
122
+ #
123
+ # @option options [Integer] :thread_count (10) Customize threads used in the multipart download.
124
+ # Only used when no custom executor is provided (creates {DefaultExecutor} with given thread count).
125
+ #
126
+ # @option options [String] :checksum_mode ("ENABLED")
127
+ # This option is deprecated. Use `:response_checksum_validation` on your S3 client instead.
128
+ # To disable checksum validation, set `response_checksum_validation: 'when_required'`
129
+ # when creating your S3 client.
130
+ #
131
+ # @option options [Callable] :on_checksum_validated
132
+ # Called each time a request's checksum is validated with the checksum algorithm and the
133
+ # response. For multipart downloads, this will be called for each part that is downloaded and validated.
134
+ #
135
+ # @option options [Proc] :progress_callback
136
+ # A Proc that will be called when each chunk of the download is received. It will be invoked with
137
+ # `bytes_read`, `part_sizes`, `file_size`. When the object is downloaded as parts (rather than by ranges),
138
+ # the `part_sizes` will not be known ahead of time and will be `nil` in the callback until the first bytes
139
+ # in the part are received.
140
+ #
141
+ # @raise [MultipartDownloadError] Raised when an object validation fails outside of service errors.
142
+ #
143
+ # @return [Boolean] Returns `true` when the file is downloaded without any errors.
144
+ #
145
+ # @see Client#get_object
146
+ # @see Client#head_object
147
+ def download_file(destination, bucket:, key:, **options)
148
+ download_opts = options.merge(bucket: bucket, key: key)
149
+ executor = @executor || DefaultExecutor.new(max_threads: download_opts.delete(:thread_count))
150
+ downloader = FileDownloader.new(client: @client, executor: executor)
151
+ downloader.download(destination, download_opts)
152
+ executor.shutdown unless @executor
153
+ true
154
+ end
155
+
156
+ # Uploads a file from disk to S3.
157
+ #
158
+ # # a small file are uploaded with PutObject API
159
+ # tm = TransferManager.new
160
+ # tm.upload_file('/path/to/small_file', bucket: 'bucket', key: 'key')
161
+ #
162
+ # Files larger than or equal to `:multipart_threshold` are uploaded using multipart upload APIs.
163
+ #
164
+ # # large files are automatically split into parts and the parts are uploaded in parallel
165
+ # tm.upload_file('/path/to/large_file', bucket: 'bucket', key: 'key')
166
+ #
167
+ # The response of the S3 upload API is yielded if a block given.
168
+ #
169
+ # # API response will have etag value of the file
170
+ # tm.upload_file('/path/to/file', bucket: 'bucket', key: 'key') do |response|
171
+ # etag = response.etag
172
+ # end
173
+ #
174
+ # You can provide a callback to monitor progress of the upload:
175
+ #
176
+ # # bytes and totals are each an array with 1 entry per part
177
+ # progress = proc do |bytes, totals|
178
+ # bytes.map.with_index do |b, i|
179
+ # puts "Part #{i + 1}: #{b} / #{totals[i]} " + "Total: #{100.0 * bytes.sum / totals.sum}%"
180
+ # end
181
+ # end
182
+ # tm.upload_file('/path/to/file', bucket: 'bucket', key: 'key', progress_callback: progress)
183
+ #
184
+ # @param [String, Pathname, File, Tempfile] source
185
+ # A file on the local file system that will be uploaded. This can either be a `String` or `Pathname` to the
186
+ # file, an open `File` object, or an open `Tempfile` object. If you pass an open `File` or `Tempfile` object,
187
+ # then you are responsible for closing it after the upload completes. When using an open Tempfile, rewind it
188
+ # before uploading or else the object will be empty.
189
+ #
190
+ # @param [String] bucket
191
+ # The name of the S3 bucket to upload to.
192
+ #
193
+ # @param [String] key
194
+ # The object key name for the uploaded file.
195
+ #
196
+ # @param [Hash] options
197
+ # Additional options for {Client#put_object} when file sizes below the multipart threshold.
198
+ # For files larger than the multipart threshold, options for {Client#create_multipart_upload},
199
+ # {Client#complete_multipart_upload}, and {Client#upload_part} can be provided.
200
+ #
201
+ # @option options [Integer] :multipart_threshold (104857600)
202
+ # Files larger han or equal to `:multipart_threshold` are uploaded using the S3 multipart upload APIs.
203
+ # Default threshold is `100MB`.
204
+ #
205
+ # @option options [Integer] :thread_count (10) Customize threads used in the multipart upload.
206
+ # Only used when no custom executor is provided (creates {DefaultExecutor} with the given thread count).
207
+ #
208
+ # @option option [Integer] :http_chunk_size (16384) Size in bytes for each chunk when streaming request bodies
209
+ # over HTTP. Controls the buffer size used when sending data to S3. Larger values may improve throughput by
210
+ # reducing the number of network writes, but use more memory. Custom values must be at least 16KB.
211
+ # Only Ruby MRI is supported.
212
+ #
213
+ # @option options [Proc] :progress_callback (nil)
214
+ # A Proc that will be called when each chunk of the upload is sent.
215
+ # It will be invoked with `[bytes_read]` and `[total_sizes]`.
216
+ #
217
+ # @raise [MultipartUploadError] If a file is being uploaded in parts, and the upload can not be completed,
218
+ # then the upload is aborted and this error is raised. The raised error has a `#errors` method that
219
+ # returns the failures that caused the upload to be aborted.
220
+ #
221
+ # @return [Boolean] Returns `true` when the file is uploaded without any errors.
222
+ #
223
+ # @see Client#put_object
224
+ # @see Client#create_multipart_upload
225
+ # @see Client#complete_multipart_upload
226
+ # @see Client#upload_part
227
+ def upload_file(source, bucket:, key:, **options)
228
+ upload_opts = options.merge(bucket: bucket, key: key)
229
+ http_chunk_size =
230
+ if defined?(JRUBY_VERSION)
231
+ nil
232
+ else
233
+ chunk = upload_opts.delete(:http_chunk_size)
234
+ if chunk && chunk < Aws::Plugins::ChecksumAlgorithm::DEFAULT_TRAILER_CHUNK_SIZE
235
+ raise ArgumentError, ':http_chunk_size must be at least 16384 bytes (16KB)'
236
+ end
237
+
238
+ chunk
239
+ end
240
+
241
+ executor = @executor || DefaultExecutor.new(max_threads: upload_opts.delete(:thread_count))
242
+ uploader = FileUploader.new(
243
+ multipart_threshold: upload_opts.delete(:multipart_threshold),
244
+ http_chunk_size: http_chunk_size,
245
+ client: @client,
246
+ executor: executor
247
+ )
248
+ response = uploader.upload(source, upload_opts)
249
+ yield response if block_given?
250
+ executor.shutdown unless @executor
251
+ true
252
+ end
253
+
254
+ # Uploads a stream in a streaming fashion to S3.
255
+ #
256
+ # Passed chunks automatically split into multipart upload parts and the parts are uploaded in parallel.
257
+ # This allows for streaming uploads that never touch the disk.
258
+ #
259
+ # **Note**: There are known issues in JRuby until jruby-9.1.15.0, so avoid using this with older JRuby versions.
260
+ #
261
+ # @example Streaming chunks of data
262
+ # tm = TransferManager.new
263
+ # tm.upload_stream(bucket: 'bucket', key: 'key') do |write_stream|
264
+ # 10.times { write_stream << 'foo' }
265
+ # end
266
+ # @example Streaming chunks of data
267
+ # tm.upload_stream(bucket: 'bucket', key: 'key') do |write_stream|
268
+ # IO.copy_stream(IO.popen('ls'), write_stream)
269
+ # end
270
+ # @example Streaming chunks of data
271
+ # tm.upload_stream(bucket: 'bucket', key: 'key') do |write_stream|
272
+ # IO.copy_stream(STDIN, write_stream)
273
+ # end
274
+ #
275
+ # @param [String] bucket
276
+ # The name of the S3 bucket to upload to.
277
+ #
278
+ # @param [String] key
279
+ # The object key name for the uploaded file.
280
+ #
281
+ # @param [Hash] options
282
+ # Additional options for {Client#create_multipart_upload}, {Client#complete_multipart_upload}, and
283
+ # {Client#upload_part} can be provided.
284
+ #
285
+ # @option options [Integer] :thread_count (10)
286
+ # The number of parallel multipart uploads. Only used when no custom executor is provided (creates
287
+ # {DefaultExecutor} with the given thread count). An additional thread is used internally for task coordination.
288
+ #
289
+ # @option options [Boolean] :tempfile (false)
290
+ # Normally read data is stored in memory when building the parts in order to complete the underlying
291
+ # multipart upload. By passing `:tempfile => true`, the data read will be temporarily stored on disk reducing
292
+ # the memory footprint vastly.
293
+ #
294
+ # @option options [Integer] :part_size (5242880)
295
+ # Define how big each part size but the last should be. Default `:part_size` is `5 * 1024 * 1024`.
296
+ #
297
+ # @raise [MultipartUploadError] If an object is being uploaded in parts, and the upload can not be completed,
298
+ # then the upload is aborted and this error is raised. The raised error has a `#errors` method that returns
299
+ # the failures that caused the upload to be aborted.
300
+ #
301
+ # @return [Boolean] Returns `true` when the object is uploaded without any errors.
302
+ #
303
+ # @see Client#create_multipart_upload
304
+ # @see Client#complete_multipart_upload
305
+ # @see Client#upload_part
306
+ def upload_stream(bucket:, key:, **options, &block)
307
+ upload_opts = options.merge(bucket: bucket, key: key)
308
+ executor = @executor || DefaultExecutor.new(max_threads: upload_opts.delete(:thread_count))
309
+ uploader = MultipartStreamUploader.new(
310
+ client: @client,
311
+ executor: executor,
312
+ tempfile: upload_opts.delete(:tempfile),
313
+ part_size: upload_opts.delete(:part_size)
314
+ )
315
+ uploader.upload(upload_opts, &block)
316
+ executor.shutdown unless @executor
317
+ true
318
+ end
319
+ end
320
+ end
321
+ end