<PackageReference Include="Microsoft.Azure.Storage.Blob" Version="11.1.5" />

Microsoft.Azure.Storage.Blob.BlobWriteStream

This class uses an algorithm designed to aid users in writing simple code that is also performant. The idea is that the caller can write the following pseudocode: using (BlobWriteStream bws = Cloud*Blob.OpenWrite()) { while (moreData) { byte[] bytes = await GetDataAsync(); await bws.WriteAsync(bytes); } } The goal here is to have this code exhibit a sort of double-buffering functionality, where "GetDataAsync()" (whatever that is) is able to run in parallel with the data upload to Azure Storage. This is accomplished via buffering data during the write, and then later uploading it to Storage. However, we also need to limit how much data is buffered, to avoid using too much memory. To do this, continuation after "await bws.WriteAsync(bytes)" will only continue if the stream hasn't buffered too much. The limit on what is "too much" depends on the size of the input bytes[] data, the block size, and the max parallelism factor. Roughly, it's the maximum of 1-2x the input byte array size, and block size * parallelism factor. It's also fuzzy depending on whether or not you include any data that's currently being processed in WriteAsync(), any data that's currently being uploaded, or just data that's stored in the stream's buffer, waiting to be uploaded. The biggest complication and/or likely location for bugs is around error handling, because errors might occur after "await WriteAsync()" has already continued. If some day we consider a library re-design / re-architect, this code would likely be opt-in.