static void CopyTo(Stream input, Stream output, int len) { var arr = new byte[4096 * 8]; while (len > 0) { int l = input.Read(arr, 0, Math.Min(len, arr.Length)); if (l == 0) throw new EndOfStreamException(); output.Write(arr, 0, l); len -= l; } }