public void DeleteBytes(long index, long length) { try { long bytesToDelete = length; long blockOffset; DataBlock block = GetDataBlock(index, out blockOffset); while ((bytesToDelete > 0) && (block != null)) { long blockLength = block.Length; DataBlock nextBlock = block.NextBlock; long count = Math.Min(bytesToDelete, blockLength - (index - blockOffset)); block.RemoveBytes(index - blockOffset, count); if (block.Length == 0) { _dataMap.Remove(block); if (_dataMap.FirstBlock == null) { _dataMap.AddFirst(new MemoryDataBlock(new byte[0])); } } bytesToDelete -= count; blockOffset += block.Length; block = (bytesToDelete > 0) ? nextBlock : null; } } finally { _totalLength -= length; OnLengthChanged(EventArgs.Empty); OnChanged(EventArgs.Empty); } }
void ReInitialize() { _dataMap = new DataMap(); _dataMap.AddFirst(new FileDataBlock(0, _stream.Length)); _totalLength = _stream.Length; }