public static async Task ReuseAfterBuild(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);
            using (var manager = await writer.GetWrittenContentAsync())
                Equal(bytes, manager.Memory.ToArray());
            await writer.WriteAsync(new byte[] { 3, 4, 5 }.AsMemory());

            writer.WriteByte(6);
            using (var manager = await writer.GetWrittenContentAsync(500..))
            {
                Equal(new byte[] { 3, 4, 5, 6 }, manager.Memory.ToArray());
            }
        }
 public static async Task WriteDuringReadAsync()
 {
     using var writer = new FileBufferingWriter();
     writer.Write(new byte[] { 1, 2, 3 });
     using var manager = writer.GetWrittenContent();
     Equal(new byte[] { 1, 2, 3 }, manager.Memory.ToArray());
     Throws <InvalidOperationException>(writer.Clear);
     Throws <InvalidOperationException>(() => writer.WriteByte(2));
     Throws <InvalidOperationException>(() => writer.GetWrittenContent());
     await ThrowsAsync <InvalidOperationException>(() => writer.WriteAsync(new byte[2], 0, 2));
     await ThrowsAsync <InvalidOperationException>(writer.GetWrittenContentAsync().AsTask);
 }