public static async Task CopyToStream() { var content = new byte[] { 1, 5, 8, 9 }; IAsyncBinaryReader reader = IAsyncBinaryReader.Create(new ChunkSequence <byte>(content, 2).ToReadOnlySequence()); using var ms = new MemoryStream(); await reader.CopyToAsync(ms); ms.Position = 0; Equal(content, ms.ToArray()); }
public static async Task CopyToPipe() { var expected = new byte[] { 1, 5, 8, 9 }; IAsyncBinaryReader reader = IAsyncBinaryReader.Create(new ChunkSequence <byte>(expected, 2).ToReadOnlySequence()); var pipe = new Pipe(); await reader.CopyToAsync(pipe.Writer); await pipe.Writer.CompleteAsync(); var actual = new byte[expected.Length]; await pipe.Reader.ReadBlockAsync(actual); Equal(expected, actual); }
Task IAsyncBinaryReader.CopyToAsync(Stream output, CancellationToken token) => reader.CopyToAsync(output, token);