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

286 Views Asked by At

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,))
2

There are 2 best solutions below

0
On BEST ANSWER

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

0
On

It appears memory mapping to a MemoryFS is a bit too abstract. This works fine using a TempFS which writes to the system temp dir on the OS storage medium.