You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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"""fromfsimportopen_fsdeftry_temp():
temp_fs=open_fs("temp://")
temp_fs.writebytes("file", b"here are some bytes")
buff=bytearray(30)
withtemp_fs.openbin("file", mode="r") asfile:
file.readinto(buff)
print(buff)
deftry_mem_1():
mem_fs=open_fs("mem://")
mem_fs.writebytes("file", b"here are some bytes")
buff=bytearray(30)
withmem_fs.openbin("file", mode="r") asfile:
print(type(file))
file.readinto(buff)
print(buff)
deftry_mem_2():
mem_fs=open_fs("mem://")
mem_fs.writebytes("file", b"here are some bytes")
buff=bytearray(30)
withmem_fs.open("file", mode="rb") asfile:
print(type(file))
file.readinto(buff)
print(buff)
try_temp() # ok, prints bufftry_mem_1() # raises NotImplementedErrortry_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.
Activity
willmcgugan commentedon Apr 9, 2020
Thanks for investigating. Implementing a readinto for memory file seems the way to go. A PR would be appreciated.