diff options
author | Andrew Leech <andrew.leech@planetinnovation.com.au> | 2023-10-31 15:14:05 +1100 |
---|---|---|
committer | Damien George <damien@micropython.org> | 2023-11-09 11:20:31 +1100 |
commit | 4cf741062b20fa34062d236d56b2168515e990b4 (patch) | |
tree | f5362f11623a29ded6d47398e5fe9f480e2f3e50 /tests/extmod/vfs_userfs.py | |
parent | dff293840e381444bcd843a325ab3dd7da685733 (diff) | |
download | micropython-4cf741062b20fa34062d236d56b2168515e990b4.tar.gz micropython-4cf741062b20fa34062d236d56b2168515e990b4.zip |
extmod/vfs_reader: Add file ioctl to set read buffer size.
Can be used to speed up importing a file from a vfs based filesystem.
Signed-off-by: Andrew Leech <andrew.leech@planetinnovation.com.au>
Diffstat (limited to 'tests/extmod/vfs_userfs.py')
-rw-r--r-- | tests/extmod/vfs_userfs.py | 18 |
1 files changed, 17 insertions, 1 deletions
diff --git a/tests/extmod/vfs_userfs.py b/tests/extmod/vfs_userfs.py index 36f1088870..5c487315eb 100644 --- a/tests/extmod/vfs_userfs.py +++ b/tests/extmod/vfs_userfs.py @@ -16,6 +16,8 @@ except (ImportError, AttributeError): class UserFile(io.IOBase): + buffer_size = 16 + def __init__(self, mode, data): assert isinstance(data, bytes) self.is_text = mode.find("b") == -1 @@ -39,7 +41,11 @@ class UserFile(io.IOBase): def ioctl(self, req, arg): print("ioctl", req, arg) - return 0 + if req == 4: # MP_STREAM_CLOSE + return 0 + if req == 11: # MP_STREAM_GET_BUFFER_SIZE + return UserFile.buffer_size + return -1 class UserFS: @@ -70,6 +76,8 @@ user_files = { "/usermod2.py": b"print('in usermod2')", "/usermod3.py": b"syntax error", "/usermod4.mpy": b"syntax error", + "/usermod5.py": b"print('in usermod5')", + "/usermod6.py": b"print('in usermod6')", } os.mount(UserFS(user_files), "/userfs") @@ -93,6 +101,14 @@ try: except ValueError: print("ValueError in usermod4") +# Test an import with largest buffer size +UserFile.buffer_size = 255 +import usermod5 + +# Test an import with over-size buffer size (should be safely limited internally) +UserFile.buffer_size = 1024 +import usermod6 + # unmount and undo path addition os.umount("/userfs") sys.path.pop() |