diff --git a/refinery/lib/structures.py b/refinery/lib/structures.py index 297e0db5d..dc5ca6c3f 100644 --- a/refinery/lib/structures.py +++ b/refinery/lib/structures.py @@ -65,7 +65,7 @@ def __exit__(self, *args): self.stream.seek(self.cursor, io.SEEK_SET) -class MemoryFile(Generic[T], io.IOBase): +class MemoryFile(Generic[T]): """ A thin wrapper around (potentially mutable) byte sequences which gives it the features of a file-like object. diff --git a/refinery/lib/vfs.py b/refinery/lib/vfs.py index 5f73bcb2a..33d7d2ef2 100644 --- a/refinery/lib/vfs.py +++ b/refinery/lib/vfs.py @@ -54,10 +54,18 @@ def mmap(self, length: int = 0, offset: int = 0) -> MemoryFile: Emulate the result of an `mmap` call to the virtual file. """ view = memoryview(self.data) + node = self.node if length: view = view[offset:offset + length] - fd = MemoryFile(view, read_as_bytes=True, fileno=self.node) - return fd + + class _MappedView(bytearray, MemoryFile): + def __init__(self): + MemoryFile.__init__(self, self, True, node) + + mapped = _MappedView() + mapped[:] = view + + return mapped def open(self, mode: str) -> MemoryFile: """