@@ -85,8 +85,7 @@ private delegate Task StageContentPartitionAsync<TContent>(
8585 /// </summary>
8686 private delegate Task < ( Stream PartitionContent , ReadOnlyMemory < byte > PartitionChecksum ) > GetNextStreamPartition (
8787 Stream stream ,
88- long minCount ,
89- long maxCount ,
88+ long count ,
9089 long absolutePosition ,
9190 bool async ,
9291 CancellationToken cancellationToken ) ;
@@ -373,14 +372,14 @@ public async Task<Response<TCompleteUploadReturn>> UploadInternal(
373372 Stream bufferedContent ;
374373 if ( UseMasterCrc && _masterCrcSupplier != default )
375374 {
376- bufferedContent = await PooledMemoryStream . BufferStreamPartitionInternal (
377- content , length . Value , length . Value , _arrayPool ,
378- maxArrayPoolRentalSize : default , async , cancellationToken ) . ConfigureAwait ( false ) ;
375+ bufferedContent = new PooledMemoryStream ( _arrayPool , Constants . MB ) ;
376+ await content . CopyToInternal ( bufferedContent , async , cancellationToken ) . ConfigureAwait ( false ) ;
377+ bufferedContent . Position = 0 ;
379378 }
380379 else
381380 {
382381 ( bufferedContent , oneshotValidationOptions ) = await BufferAndOptionalChecksumStreamInternal (
383- content , length . Value , length . Value , oneshotValidationOptions , async, cancellationToken )
382+ content , length . Value , oneshotValidationOptions , async, cancellationToken )
384383 . ConfigureAwait ( false ) ;
385384 }
386385 bucket . Add ( bufferedContent ) ;
@@ -438,11 +437,8 @@ private static long GetActualBlockSize(long? blockSize, long? totalLength)
438437 /// <param name="source">
439438 /// Stream to buffer.
440439 /// </param>
441- /// <param name="minCount">
442- /// Minimum count to buffer from the stream.
443- /// </param>
444- /// <param name="maxCount">
445- /// Maximum count to buffer from the stream.
440+ /// <param name="count">
441+ /// Exact count to buffer from the stream.
446442 /// </param>
447443 /// <param name="validationOptions">
448444 /// Validation options for the upload to determine if buffering is needed.
@@ -467,8 +463,7 @@ private static long GetActualBlockSize(long? blockSize, long? totalLength)
467463 private async Task < ( Stream Stream , UploadTransferValidationOptions ValidationOptions ) >
468464 BufferAndOptionalChecksumStreamInternal (
469465 Stream source ,
470- long minCount ,
471- long maxCount ,
466+ long ? count ,
472467 UploadTransferValidationOptions validationOptions ,
473468 bool async ,
474469 CancellationToken cancellationToken )
@@ -488,14 +483,16 @@ private static long GetActualBlockSize(long? blockSize, long? totalLength)
488483 . SetupChecksumCalculatingReadStream ( source , validationOptions . ChecksumAlgorithm ) ;
489484 }
490485
491- PooledMemoryStream bufferedContent = await PooledMemoryStream . BufferStreamPartitionInternal (
492- source ,
493- minCount ,
494- maxCount ,
495- _arrayPool ,
496- maxArrayPoolRentalSize : default ,
497- async,
498- cancellationToken ) . ConfigureAwait ( false ) ;
486+ Stream bufferedContent = new PooledMemoryStream ( _arrayPool , Constants . MB ) ;
487+ if ( count . HasValue )
488+ {
489+ await source . CopyToExactInternal ( bufferedContent , count . Value , async, cancellationToken ) . ConfigureAwait ( false ) ;
490+ }
491+ else
492+ {
493+ await source . CopyToInternal ( bufferedContent , async , cancellationToken ) . ConfigureAwait( false ) ;
494+ }
495+ bufferedContent . Position = 0 ;
499496
500497 if ( usingChecksumStream )
501498 {
@@ -893,12 +890,6 @@ private static async IAsyncEnumerable<ContentPartition<Stream>> GetStreamPartiti
893890 bool async ,
894891 [ EnumeratorCancellation ] CancellationToken cancellationToken )
895892 {
896- // The minimum amount of data we'll accept from a stream before
897- // splitting another block. Code that sets `blockSize` will always
898- // set it to a positive number. Min() only avoids edge case where
899- // user sets their block size to 1.
900- long acceptableBlockSize = Math . Max ( 1 , blockSize / 2 ) ;
901-
902893 // if we know the data length, assert boundaries before spending resources uploading beyond service capabilities
903894 if ( streamLength . HasValue )
904895 {
@@ -910,8 +901,6 @@ private static async IAsyncEnumerable<ContentPartition<Stream>> GetStreamPartiti
910901 {
911902 throw Errors . InsufficientStorageTransferOptions ( streamLength . Value , blockSize , minRequiredBlockSize ) ;
912903 }
913- // bring min up to our min required by the service
914- acceptableBlockSize = Math . Max ( acceptableBlockSize , minRequiredBlockSize ) ;
915904 }
916905
917906 long read ;
@@ -920,7 +909,6 @@ private static async IAsyncEnumerable<ContentPartition<Stream>> GetStreamPartiti
920909 {
921910 ( Stream partition , ReadOnlyMemory < byte > partitionChecksum ) = await getNextPartition (
922911 stream ,
923- acceptableBlockSize ,
924912 blockSize ,
925913 absolutePosition ,
926914 async ,
@@ -954,11 +942,8 @@ private static async IAsyncEnumerable<ContentPartition<Stream>> GetStreamPartiti
954942 /// <param name="stream">
955943 /// Stream to buffer a partition from.
956944 /// </param>
957- /// <param name="minCount">
958- /// Minimum amount of data to wait on before finalizing buffer.
959- /// </param>
960- /// <param name="maxCount">
961- /// Max amount of data to buffer before cutting off for the next.
945+ /// <param name="count">
946+ /// Amount of data to wait on before finalizing buffer.
962947 /// </param>
963948 /// <param name="absolutePosition">
964949 /// Offset of this stream relative to the large stream.
@@ -974,8 +959,7 @@ private static async IAsyncEnumerable<ContentPartition<Stream>> GetStreamPartiti
974959 /// </returns>
975960 private async Task < ( Stream PartitionContent , ReadOnlyMemory < byte > PartitionChecksum ) > GetBufferedPartitionInternal (
976961 Stream stream ,
977- long minCount ,
978- long maxCount ,
962+ long count ,
979963 long absolutePosition ,
980964 bool async ,
981965 CancellationToken cancellationToken )
@@ -984,8 +968,7 @@ private static async IAsyncEnumerable<ContentPartition<Stream>> GetStreamPartiti
984968 ( Stream slicedStream , UploadTransferValidationOptions validationOptions )
985969 = await BufferAndOptionalChecksumStreamInternal (
986970 stream ,
987- minCount ,
988- maxCount ,
971+ count ,
989972 new UploadTransferValidationOptions { ChecksumAlgorithm = _validationAlgorithm } ,
990973 async,
991974 cancellationToken ) . ConfigureAwait ( false ) ;
@@ -1002,10 +985,7 @@ private static async IAsyncEnumerable<ContentPartition<Stream>> GetStreamPartiti
1002985 /// <param name="stream">
1003986 /// Stream to wrap.
1004987 /// </param>
1005- /// <param name="minCount">
1006- /// Unused, but part of <see cref="GetNextStreamPartition"/> definition.
1007- /// </param>
1008- /// <param name="maxCount">
988+ /// <param name="count">
1009989 /// Length of this facade stream.
1010990 /// </param>
1011991 /// <param name="absolutePosition">
@@ -1020,8 +1000,7 @@ private static async IAsyncEnumerable<ContentPartition<Stream>> GetStreamPartiti
10201000 /// </returns>
10211001 private async Task < ( Stream PartitionContent , ReadOnlyMemory < byte > PartitionChecksum ) > GetStreamedPartitionInternal (
10221002 Stream stream ,
1023- long minCount ,
1024- long maxCount ,
1003+ long count ,
10251004 long absolutePosition ,
10261005 bool async ,
10271006 CancellationToken cancellationToken )
@@ -1030,7 +1009,7 @@ private static async IAsyncEnumerable<ContentPartition<Stream>> GetStreamPartiti
10301009 {
10311010 throw Errors . InvalidArgument ( nameof ( stream ) ) ;
10321011 }
1033- var partitionStream = WindowStream . GetWindow ( stream , maxCount ) ;
1012+ var partitionStream = WindowStream . GetWindow ( stream , count ) ;
10341013 // this resets stream position for us
10351014 var checksum = await ContentHasher . GetHashOrDefaultInternal (
10361015 partitionStream ,
0 commit comments