Search code examples
pythonnumpymemory-mapped-filespyfilesystem

How to work with memory mapped files (numpy.memmap) in PyFilesystem?


Can I use PyFilesystem with numpy memory mapped files? The sample code below throws io.UnsupportedOperation: fileno which is due to PyFilesystem throwing the unsupported exception for the fileno operation on the IO Stream object.

import numpy as np
import fs.memoryfs as fs

memfs = fs.MemoryFS()
with memfs.open('/test.dat', 'wb+') as file:
    np.memmap(file, dtype=np.int, mode='r+', shape=(1,))

Solution

  • Only regular system files can be memory mapped. So you are restricted to OSFS, and TempFS.