public byte[] GetChunk(long HeadBufferNumber)
{
// get the head, interpret the length
byte buffertype;
long nextBufferNumber;
byte[] buffer = this.ParseBuffer(HeadBufferNumber, out buffertype, out nextBufferNumber);
int length = BufferFile.Retrieve(buffer, 0);
if (length<0)
{
throw new LinkedFileException("negative length block? must be garbage: "+length);
}
if (buffertype!=HEAD)
{
throw new LinkedFileException("first buffer not marked HEAD");
}
byte[] result = new byte[length];
// read in the data from the first buffer
int firstLength = this.buffersize-BufferFile.INTSTORAGE;
if (firstLength>length)
{
firstLength = length;
}
Array.Copy(buffer, BufferFile.INTSTORAGE, result, 0, firstLength);
int stored = firstLength;
while (stored<length)
{
// get the next buffer
long thisBufferNumber = nextBufferNumber;
buffer = this.ParseBuffer(thisBufferNumber, out buffertype, out nextBufferNumber);
int nextLength = this.buffersize;
if (length-stored<nextLength)
{
nextLength = length-stored;
}
Array.Copy(buffer, 0, result, stored, nextLength);
stored += nextLength;
}
return result;
}