Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
MemoryFileSystem: seek to end when creating a file in append mode
Per review: explicitly position the append-created file at the end, matching
the existing-file append path, instead of relying on the new file being empty.
Assert the position in the regression test.
  • Loading branch information
Sreekant13 committed Jul 4, 2026
commit 9bcb8fda9e1fde22145b4340a82baa194753eb1f
2 changes: 2 additions & 0 deletions fsspec/implementations/memory.py
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,8 @@ def _open(
m = MemoryFile(self, path, kwargs.get("data"))
if not self._intrans:
m.commit()
Comment on lines +203 to +205

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should make sure to seek to the end of the file. In the test, it is already at the end, but this is not guaranteed.

# position at the end of file, like the existing-file path above
m.seek(0, 2)
return m
else:
raise FileNotFoundError(path)
Expand Down
2 changes: 2 additions & 0 deletions fsspec/implementations/tests/test_memory.py
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,8 @@ def test_append_creates_missing_file(m, mode):
filename = "newfile.txt"
assert not m.exists(filename)
with m.open(filename, mode) as f:
# append mode must position at the end of the (newly created) file
assert f.tell() == f.seek(0, 2)
f.write(b"data" if "b" in mode else "data")
assert m.cat(filename) == b"data"

Expand Down