protected override void Write(MemoryStream data) { var toWrite = (int)(data.Length - data.Position); Chain.WriteData(0, data); var trueSize = Chain.GetLengthOnDisk(); /* TODO: check if the code below is really needed */ if (trueSize > toWrite) { var rest = (int)(trueSize - toWrite); var fill = new MemoryStream(rest); Chain.WriteData(toWrite, fill); } }
/// <summary> /// If the data to be written extends beyond the current /// <see cref="GetLength"/> length of this file, an attempt is made to /// <see cref="SetLength(long)"/> grow the file so that the data will fit. /// Additionally, this method updates the "last accessed" and "last modified" /// fields on the directory entry that is associated with this file. /// </summary> /// <param name="offset"></param> /// <param name="srcBuf"></param> public void Write(long offset, MemoryStream srcBuf) { CheckWritable(); UpdateTimeStamps(true); var lastByte = offset + (srcBuf.Length - srcBuf.Position); if (lastByte > GetLength()) { SetLength(lastByte); } chain.WriteData(offset, srcBuf); }