/// <summary> /// Initializes a chunked upload stream with one or more trailing headers, /// which may include a trailing checksum header /// </summary> /// <param name="stream">Stream to wrap</param> /// <param name="wrappedStreamBufferSize">Size of buffer used for reading from stream</param> /// <param name="headerSigningResult">SigV4 or SigV4a signing result for the request's headers</param> /// <param name="trailingChecksum">Algorithm to use to calculate the stream's checksum</param> /// <param name="trailingHeaders">Trailing headers to append after the wrapped stream</param> public ChunkedUploadWrapperStream(Stream stream, int wrappedStreamBufferSize, AWSSigningResultBase headerSigningResult, CoreChecksumAlgorithm trailingChecksum, IDictionary <string, string> trailingHeaders) : this(stream, wrappedStreamBufferSize, headerSigningResult) { if (trailingChecksum != CoreChecksumAlgorithm.NONE) { _trailingChecksum = trailingChecksum; _hashAlgorithm = CryptoUtilFactory.GetChecksumInstance(trailingChecksum); } _trailingHeadersConsumed = false; _trailingHeaders = trailingHeaders; }
/// <summary> /// Initializes a chunked upload stream /// </summary> /// <param name="stream">stream to wrap</param> /// <param name="wrappedStreamBufferSize">Size of buffer used for reading from stream</param> /// <param name="headerSigningResult">SigV4 or SigV4a signing result for the request's headers</param> internal ChunkedUploadWrapperStream(Stream stream, int wrappedStreamBufferSize, AWSSigningResultBase headerSigningResult) : base(stream) { if (!(headerSigningResult is AWS4aSigningResult || headerSigningResult is AWS4SigningResult)) { throw new AmazonClientException($"{nameof(ChunkedUploadWrapperStream)} was initialized without a SigV4 or SigV4a signing result."); } else if (headerSigningResult is AWS4aSigningResult) { Sigv4aSigner = new AWS4aSignerCRTWrapper(); } HeaderSigningResult = headerSigningResult; PreviousChunkSignature = headerSigningResult?.Signature; _wrappedStreamBufferSize = wrappedStreamBufferSize; _inputBuffer = new byte[DefaultChunkSize]; _outputBuffer = new byte[CalculateChunkHeaderLength(DefaultChunkSize, HeaderSigningResult is AWS4aSigningResult ? V4A_SIGNATURE_LENGTH : V4_SIGNATURE_LENGTH)]; // header+data // if the wrapped stream implements encryption, switch to a read-and-copy // strategy for filling the chunk buffer var encryptionStream = SearchWrappedStream(s => { var encryptUploadPartStream = s as EncryptUploadPartStream; if (encryptUploadPartStream != null) { return(true); } var encryptStream = s as EncryptStream; return(encryptStream != null); }); if (encryptionStream != null) { _readStrategy = ReadStrategy.ReadAndCopy; } }