OpenSim.Framework.WebUtil.CopyTo C# (CSharp) Method

CopyTo() public static method

Copies the contents of one stream to another, starting at the current position of each stream
Copying begins at the streams' current positions. The positions are NOT reset after copying is complete.
public static CopyTo ( this copyFrom, Stream copyTo, int maximumBytesToCopy ) : int
copyFrom this The stream to copy from, at the position /// where copying should begin
copyTo Stream The stream to copy to, at the position where /// bytes should be written
maximumBytesToCopy int The maximum bytes to copy
return int
        public static int CopyTo(this Stream copyFrom, Stream copyTo, int maximumBytesToCopy)
        {
            byte[] buffer = new byte[4096];
            int readBytes;
            int totalCopiedBytes = 0;

            while ((readBytes = copyFrom.Read(buffer, 0, Math.Min(4096, maximumBytesToCopy))) > 0)
            {
                int writeBytes = Math.Min(maximumBytesToCopy, readBytes);
                copyTo.Write(buffer, 0, writeBytes);
                totalCopiedBytes += writeBytes;
                maximumBytesToCopy -= writeBytes;
            }

            return totalCopiedBytes;
        }