Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create minimum buffer required for OpenRead #47958

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ public LazyLoadingReadOnlyStream(
GetPropertiesAsync getPropertiesFunc,
DownloadTransferValidationOptions transferValidation,
bool allowModifications,
long initialLenght,
long initialLength,
long position = 0,
int? bufferSize = default,
PredictEncryptedRangeAdjustment rangePredictionFunc = default)
Expand All @@ -148,12 +148,16 @@ public LazyLoadingReadOnlyStream(
_getPropertiesInternalFunc = getPropertiesFunc;
_predictEncryptedRangeAdjustment = rangePredictionFunc ?? (range => range);
_position = position;
_bufferSize = bufferSize ?? Constants.DefaultStreamingDownloadSize;

// If the blob cannot be modified and the total blob size is less than the default streaming size,
// the buffer size should be limited to the total blob size.
int maxBufferSize = allowModifications ? Constants.DefaultStreamingDownloadSize : (int)Math.Min(initialLength, Constants.DefaultStreamingDownloadSize);
_bufferSize = bufferSize ?? maxBufferSize;
_buffer = ArrayPool<byte>.Shared.Rent(_bufferSize);
_allowBlobModifications = allowModifications;
_bufferPosition = 0;
_bufferLength = 0;
_length = initialLenght;
_length = initialLength;
_bufferInvalidated = false;

// the caller to this stream cannot defer validation, as they cannot access a returned hash
Expand Down
Loading