コード例 #1
0
 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());
         }
 }
コード例 #2
0
 public static void CopyTo(this IReadable readable, Stream dest)
 {
     using (var s = readable.OpenReader())
     {
         s.CopyTo(dest);
         dest.Flush();
     }
 }
コード例 #3
0
        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());
                }
        }
コード例 #4
0
        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);
            }
        }
コード例 #5
0
 public void Run()
 {
     using var input = _readable.OpenReader();
     Result          = Compressor.Compress(input, Temp);
 }