public static long CopyTo(this Stream from, Stream to)
{
byte[] buffer = new byte[2048];
int bytesRead;
long totalBytes = 0;
while ((bytesRead = from.Read(buffer, 0, buffer.Length)) > 0)
{
to.Write(buffer, 0, bytesRead);
totalBytes += bytesRead;
}
return totalBytes;
}