ServiceStack.StreamExtensions.WriteTo C# (CSharp) Method

WriteTo() public static method

public static WriteTo ( this inStream, Stream outStream ) : long
inStream this
outStream Stream
return long
        public static long WriteTo(this Stream inStream, Stream outStream)
        {
            var memoryStream = inStream as MemoryStream;
            if (memoryStream != null)
            {
                memoryStream.WriteTo(outStream);
                return memoryStream.Position;
            }

            var data = new byte[4096];
            long total = 0;
            int bytesRead;

            while ((bytesRead = inStream.Read(data, 0, data.Length)) > 0)
            {
                outStream.Write(data, 0, bytesRead);
                total += bytesRead;
            }

            return total;
        }