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_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.

16_384

Instance Method Summary collapse

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.

[View source]

457
458
459
460
461
462
463
# File 'lib/aws-sdk-core/plugins/checksum_algorithm.rb', line 457

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.

[View source]

482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
# File 'lib/aws-sdk-core/plugins/checksum_algorithm.rb', line 482

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

#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.

[View source]

478
479
480
# File 'lib/aws-sdk-core/plugins/checksum_algorithm.rb', line 478

def rewind
  @io.rewind
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

[View source]

466
467
468
469
470
471
472
473
474
475
476
# File 'lib/aws-sdk-core/plugins/checksum_algorithm.rb', line 466

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