pyfilesystem2
pyfilesystem2 copied to clipboard
ZipFS cannot remove files
It would appear that the ZipFS simply lacks the ability to remove files.
with tempfile.TemporaryDirectory() as tmp_path:
tmp_path = Path(tmp_path)
with zipfile.ZipFile(tmp_path / "test.zip", "w") as zf:
zf.writestr("1.txt", "Some zip contents")
with ZipFS(str(tmp_path / "test.zip"), write=True) as zf:
print(zf.tree())
zf.remove("1.txt")
On OSX, this gives the error:
FileNotFoundError: [Errno 2] No such file or directory: b'/var/folders/00/kpyxc1gs2x7fm7g6r1_h5mcc0000gp/T/tmpdjec5u7t__ziptemp__/1.txt'
Since it would seem that the implementation of the WriteZipFS is just to create an empty temp directory and then zip it up when it's done, it makes sense that removing files from an existing archive wouldn't work... Perhaps it should copy any existing files from the zip into the temp FS when it's created?