public async static Task CopyToAsync( this IReadableByteStream stream, IWriteableByteStream dest) { var buf = Buffers.Pool.Rent(64 * 1024); var bytesRead = 0; try { while (true) { var res = await stream.ReadAsync(new ArraySegment <byte>(buf)); if (res.BytesRead != 0) { await dest.WriteAsync(new ArraySegment <byte>(buf, 0, res.BytesRead)); bytesRead += res.BytesRead; } if (res.EndOfStream) { return; } } } finally { Buffers.Pool.Return(buf); } }
/// <summary> /// Writes the preface to the given stream /// </summary> public static Task WriteAsync(IWriteableByteStream stream) { return(stream.WriteAsync(new ArraySegment <byte>(Bytes))); }