Facebook.Extensions.CopyToStream C# (CSharp) Method

CopyToStream() static private method

static private CopyToStream ( this source, Stream destination ) : void
source this
destination Stream
return void
        internal static void CopyToStream(this Stream source, Stream destination)
        {
            if (!source.CanRead)
                throw new InvalidOperationException("Cannot read from source stream.");
            if (!destination.CanWrite)
                throw new InvalidOperationException("Cannot write to target stream.");

            byte[] buffer = new byte[4096];
            int bytesRead = 0;
            while ((bytesRead = source.Read(buffer, 0, buffer.Length)) != 0)
            {
                destination.Write(buffer, 0, bytesRead);
            }
        }