I am working on a script in Python that maps a file for processing using mmap().
The tasks requires me to change the file's contents by
Replacing data works great as long as the old data and the new data have the same number of bytes:
VDATA = mmap.mmap(f.fileno(),0)
start = 10
end = 20
VDATA[start:end] = "0123456789"
However, when I try to remove data (replacing the range with "") or inserting data (replacing the range with contents longer than the range), I receive the error message:
IndexError: mmap slice assignment is wrong size
This makes sense.
The question now is, how can I insert and delete data from the mmap'ed file? Читая документацию, мне кажется, что я могу перемещать все содержимое файла вперед и назад, используя цепочку низкоуровневых действий, но я бы предпочел избежать этого, если есть более простое решение.