Class: Aws::Plugins::ChecksumAlgorithm::AwsChunkedTrailerDigestIO Private

Inherits:
Object
  • Object
show all
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_OVERHEAD =

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.

“rnrn”

4
HEX_BASE =

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.

16

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ 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.



486
487
488
489
490
491
492
493
494
495
496
497
# File 'lib/aws-sdk-core/plugins/checksum_algorithm.rb', line 486

def initialize(options = {})
  @io = options.delete(:io)
  @io.rewind if @io.respond_to?(:rewind)
  @location_name = options.delete(:location_name)
  @algorithm = options.delete(:algorithm)
  @digest = ChecksumAlgorithm.digest_for_algorithm(@algorithm)
  @chunk_size = Thread.current[:net_http_override_body_stream_chunk] || DEFAULT_TRAILER_CHUNK_SIZE
  @overhead_bytes = calculate_overhead(@chunk_size)
  @base_chunk_size = @chunk_size - @overhead_bytes
  @encoded_buffer = +''
  @eof = false
end

Instance Method Details

#eof?Boolean

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:

  • (Boolean)


540
541
542
# File 'lib/aws-sdk-core/plugins/checksum_algorithm.rb', line 540

def eof?
  @eof && @encoded_buffer.empty?
end

#read(length = nil, 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.



521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
# File 'lib/aws-sdk-core/plugins/checksum_algorithm.rb', line 521

def read(length = nil, buf = nil)
  return '' if length&.zero?
  return if eof?

  buf&.clear
  output_buffer = buf || +''

  fill_encoded_buffer(length)

  if length
    output_buffer << @encoded_buffer.slice!(0, length)
  else
    output_buffer << @encoded_buffer
    @encoded_buffer.clear
  end

  output_buffer.empty? && eof? ? nil : output_buffer
end

#rewindObject

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.



514
515
516
517
518
519
# File 'lib/aws-sdk-core/plugins/checksum_algorithm.rb', line 514

def rewind
  @io.rewind
  @encoded_buffer = +''
  @eof = false
  @digest = ChecksumAlgorithm.digest_for_algorithm(@algorithm)
end

#sizeObject

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



500
501
502
503
504
505
506
507
508
509
510
511
512
# File 'lib/aws-sdk-core/plugins/checksum_algorithm.rb', line 500

def size
  orig_body_size = @io.size
  n_full_chunks = orig_body_size / @base_chunk_size
  partial_bytes = orig_body_size % @base_chunk_size

  full_chunk_overhead = @base_chunk_size.to_s(HEX_BASE).size + CHUNK_OVERHEAD
  chunked_body_size = n_full_chunks * (@base_chunk_size + full_chunk_overhead)
  unless partial_bytes.zero?
    chunked_body_size += partial_bytes.to_s(HEX_BASE).size + partial_bytes + CHUNK_OVERHEAD
  end
  trailer_size = ChecksumAlgorithm.trailer_length(@algorithm, @location_name)
  chunked_body_size + trailer_size
end