public static void CopyBytes(IRandomAccessSource source, long start, long length, Stream outs) { if (length <= 0) return; long idx = start; byte[] buf = new byte[8192]; while (length > 0) { long n = source.Get(idx, buf,0, (int)Math.Min((long)buf.Length, length)); if (n <= 0) throw new EndOfStreamException(); outs.Write(buf, 0, (int)n); idx += n; length -= n; } }