public async Task BufferingWriterAsync() { using var writer = new FileBufferingWriter(memoryThreshold: MemoryThreshold, asyncIO: true); foreach (var chunk in GetChunks()) { await writer.WriteAsync(chunk); } await writer.FlushAsync(); using var ms = new MemoryStream(content.Length); await writer.CopyToAsync(ms); }
public static async Task DrainToBufferAsync(int threshold) { using var writer = new FileBufferingWriter(memoryThreshold: threshold, asyncIO: true); var bytes = new byte[500]; for (byte i = 0; i < byte.MaxValue; i++) { bytes[i] = i; } await writer.WriteAsync(bytes, 0, byte.MaxValue); await writer.WriteAsync(bytes.AsMemory(byte.MaxValue)); Equal(bytes.Length, writer.Length); var ms = new ArrayBufferWriter <byte>(); await writer.CopyToAsync(ms); Equal(bytes, ms.WrittenSpan.ToArray()); }