I have small chunk of code for uploading a video file by reading the file in chunks and transferring it to the API. E.g. simplified
while (someflag)
{
// open file stream
reader.Seek(counterHowMuchIsTransferred, SeekOrigin.Begin);
var buffer = ArrayPool<byte>.Shared.Rent(chunkSize);
await reader.ReadAsync(buffer.AsMemory(), cancellationToken);
}
Now the problem is that ArrayPool<T>.Shared.Rent() returns minimum requested size, which most of the times returns bigger array and breaks the file upload. How can I fix that without allocating new array every time new byte[chunkSize] because the chunkSize is always over 85K and it will be allocated on LOH.