public byte[] ToArray()
{
long len = this.Length;
if (int.MaxValue < len)
throw new OutOfMemoryException("Length exceeds maximum array size");
byte[] @out = new byte[(int)len];
if (_blocks != null)
{
int outPtr = 0;
foreach (Block b in _blocks)
{
Array.Copy(b.buffer, 0, @out, outPtr, b.count);
outPtr += b.count;
}
}
else
{
using (var @in = new FileStream(_onDiskFile.FullName, System.IO.FileMode.Open, FileAccess.Read))
{
IO.ReadFully(@in, @out, 0, (int)len);
}
}
return @out;
}