void MoveValuesContent(AbstractBufferedWriter writer, uint wastefullFileId) { const uint blockSize = 128 * 1024; var wasteFullStream = _keyValueDB.FileCollection.GetFile(wastefullFileId); var totalSize = wasteFullStream.GetSize(); var blocks = (int)((totalSize + blockSize - 1) / blockSize); var wasteInMemory = new byte[blocks][]; var pos = 0UL; for (var i = 0; i < blocks; i++) { _cancellation.ThrowIfCancellationRequested(); wasteInMemory[i] = new byte[blockSize]; var readSize = totalSize - pos; if (readSize > blockSize) readSize = blockSize; wasteFullStream.RandomRead(wasteInMemory[i], 0, (int)readSize, pos); pos += readSize; } _root.Iterate((valueFileId, valueOfs, valueSize) => { if (valueFileId != wastefullFileId) return; var size = (uint)Math.Abs(valueSize); _newPositionMap.Add(((ulong)wastefullFileId << 32) | valueOfs, (uint)writer.GetCurrentPosition()); pos = valueOfs; while (size > 0) { _cancellation.ThrowIfCancellationRequested(); var blockId = pos / blockSize; var blockStart = pos % blockSize; var writeSize = (uint)(blockSize - blockStart); if (writeSize > size) writeSize = size; writer.WriteBlock(wasteInMemory[blockId], (int)blockStart, (int)writeSize); size -= writeSize; pos += writeSize; } }); }