Closed
Description
First, many thanks for maintaining this great library!
It appears that MemoryFS
file objects are missing the readinto
method. This is tested on Python 3.6:
"""Investigate the readinto method issue with MemoryFS"""
from fs import open_fs
def try_temp():
temp_fs = open_fs("temp://")
temp_fs.writebytes("file", b"here are some bytes")
buff = bytearray(30)
with temp_fs.openbin("file", mode="r") as file:
file.readinto(buff)
print(buff)
def try_mem_1():
mem_fs = open_fs("mem://")
mem_fs.writebytes("file", b"here are some bytes")
buff = bytearray(30)
with mem_fs.openbin("file", mode="r") as file:
print(type(file))
file.readinto(buff)
print(buff)
def try_mem_2():
mem_fs = open_fs("mem://")
mem_fs.writebytes("file", b"here are some bytes")
buff = bytearray(30)
with mem_fs.open("file", mode="rb") as file:
print(type(file))
file.readinto(buff)
print(buff)
try_temp() # ok, prints buff
try_mem_1() # raises NotImplementedError
try_mem_2() # raises NotImplementedError
In the case of try_mem_2
, file
is an instance of fs.iotools.RawWrapper
, which appears to check if the underlying file has readinto
by checking for AttributeError
. It appears that in the case of _MemoryFile
it ends falling back to the "stub" readinto
method, which exists, but raises NotImplementedError
.
I am happy to prepare a PR adding readinto
to _MemoryFile
or checking for NotImplementedError
in RawWrapper
.
Thoughts?