static int CopyFileAcross(Stream instream, Stream copystream, long leftforthis)
{
int success = 1;
byte[] diskbuffer = new byte[NativeConstants.CHUNKSIZE + 10];
while (leftforthis > 0)
{
if (leftforthis > NativeConstants.CHUNKSIZE)
{
instream.Read(diskbuffer, 0, NativeConstants.CHUNKSIZE);
try
{
copystream.Write(diskbuffer, 0, NativeConstants.CHUNKSIZE);
}
catch
{
success = 0;
}
finally
{
success = 1;
}
leftforthis -= NativeConstants.CHUNKSIZE;
}
else
{
instream.Read(diskbuffer, 0, (int)leftforthis);
try
{
copystream.Write(diskbuffer, 0, (int)leftforthis);
}
catch
{
success = 0;
}
finally
{
success = 1;
}
leftforthis = 0;
}
if (success < 1) break;
}
return success;
}