public static void CopyTo(this Stream sourceStream, Stream targetStream, int sourceIndex, long length)
{
if (targetStream != null)
{
long longlength = length;
byte[] buffer = GetBuffer(sourceStream, sourceIndex);
if (buffer.Length < longlength)
{
longlength = buffer.Length;
}
int ln = 0;
//Okay, I'm nuts to do this--but I guess I like to plan for all contingencies.
do
{
if (longlength < int.MaxValue)
{
ln = Convert.ToInt32(longlength);
longlength = 0;
}
else
{
ln = int.MaxValue;
longlength -= int.MaxValue;
}
targetStream.Write(buffer, 0, ln);
} while (longlength > 0);
}
}
public static MemoryStream GetMemoryStream(this Stream stream, int index)