public void writeTo(Stream os, ProgressMonitor pm)
{
if (pm == null)
pm = new NullProgressMonitor();
if (_blocks != null)
{
// Everything is in core so we can stream directly to the output.
//
foreach (Block b in _blocks)
{
os.Write(b.buffer, 0, b.count);
pm.Update(b.count / 1024);
}
}
else
{
// Reopen the temporary file and copy the contents.
//
using (var @in = new FileStream(_onDiskFile.FullName, System.IO.FileMode.Open, FileAccess.Read))
{
int cnt;
byte[] buf = new byte[Block.SZ];
while ((cnt = @in.Read(buf, 0, buf.Length)) > 0)
{
os.Write(buf, 0, cnt);
pm.Update(cnt / 1024);
}
}
}
}