Class: Aws::Plugins::ChecksumAlgorithm::AwsChunkedTrailerDigestIO Private
- Inherits:
-
Object
- Object
- Aws::Plugins::ChecksumAlgorithm::AwsChunkedTrailerDigestIO
- Defined in:
- lib/aws-sdk-core/plugins/checksum_algorithm.rb
Overview
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.
Wrapper for request body that implements application-layer chunking with Digest computed on chunks + added as a trailer
Constant Summary collapse
- 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.
16384
Instance Method Summary collapse
-
#initialize(io, algorithm, location_name) ⇒ AwsChunkedTrailerDigestIO
constructor
private
A new instance of AwsChunkedTrailerDigestIO.
- #read(length, buf = nil) ⇒ Object private
- #rewind ⇒ Object private
-
#size ⇒ Object
private
the size of the application layer aws-chunked + trailer body.
Constructor Details
#initialize(io, algorithm, location_name) ⇒ AwsChunkedTrailerDigestIO
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 AwsChunkedTrailerDigestIO.
295 296 297 298 299 300 301 |
# File 'lib/aws-sdk-core/plugins/checksum_algorithm.rb', line 295 def initialize(io, algorithm, location_name) @io = io @location_name = location_name @algorithm = algorithm @digest = ChecksumAlgorithm.digest_for_algorithm(algorithm) @trailer_io = nil end |
Instance Method Details
#read(length, buf = nil) ⇒ 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.
320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 |
# File 'lib/aws-sdk-core/plugins/checksum_algorithm.rb', line 320 def read(length, buf = nil) # account for possible leftover bytes at the end, if we have trailer bytes, send them if @trailer_io return @trailer_io.read(length, buf) end chunk = @io.read(length) if chunk @digest.update(chunk) application_chunked = "#{chunk.bytesize.to_s(16)}\r\n#{chunk}\r\n" return StringIO.new(application_chunked).read(application_chunked.size, buf) else trailers = {} trailers[@location_name] = @digest.base64digest trailers = trailers.map { |k,v| "#{k}:#{v}"}.join("\r\n") @trailer_io = StringIO.new("0\r\n#{trailers}\r\n\r\n") chunk = @trailer_io.read(length, buf) end chunk end |
#rewind ⇒ 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.
316 317 318 |
# File 'lib/aws-sdk-core/plugins/checksum_algorithm.rb', line 316 def rewind @io.rewind end |
#size ⇒ 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.
the size of the application layer aws-chunked + trailer body
304 305 306 307 308 309 310 311 312 313 314 |
# File 'lib/aws-sdk-core/plugins/checksum_algorithm.rb', line 304 def size # compute the number of chunks # a full chunk has 4 + 4 bytes overhead, a partial chunk is len.to_s(16).size + 4 orig_body_size = @io.size n_full_chunks = orig_body_size / CHUNK_SIZE partial_bytes = orig_body_size % CHUNK_SIZE chunked_body_size = n_full_chunks * (CHUNK_SIZE + 8) chunked_body_size += partial_bytes.to_s(16).size + partial_bytes + 4 unless partial_bytes.zero? trailer_size = ChecksumAlgorithm.trailer_length(@algorithm, @location_name) chunked_body_size + trailer_size end |