public static byte[] ReadAllBytes(this IReadable readable) { if (readable is ILengthAwareReadable knowsSize) { var result = new byte[knowsSize.Length]; using (var s = readable.OpenReader()) s.Read(result, 0, result.Length); return(result); } using (var mem = new MemoryStream()) using (var s = readable.OpenReader()) { s.CopyTo(mem); return(mem.ToArray()); } }
public static void CopyTo(this IReadable readable, Stream dest) { using (var s = readable.OpenReader()) { s.CopyTo(dest); dest.Flush(); } }
public static async Task <byte[]> ReadAllBytesAsync(this IReadable readable, CancellationToken ct) { if (readable is ILengthAwareReadable knowsSize) { var result = new byte[knowsSize.Length]; using (var s = readable.OpenReader()) await s.ReadAsync(result, 0, result.Length, ct); return(result); } using (var mem = new MemoryStream()) using (var s = readable.OpenReader()) { await s.CopyToAsync(mem, DefaultStreamCopyBufferSize, ct); return(mem.ToArray()); } }
public static async Task CopyToAsync(this IReadable readable, Stream dest, CancellationToken ct) { using (var s = readable.OpenReader()) { await s.CopyToAsync(dest, DefaultStreamCopyBufferSize, ct); await dest.FlushAsync(ct); } }
public void Run() { using var input = _readable.OpenReader(); Result = Compressor.Compress(input, Temp); }