ZipFS

Use ZipFS to read and write .zip files.

Here's how you could create a zip file:

>>> from fs import open_fs
>>> with open_fs('zip://test.zip', create=True) as zip_fs:
...     zip_fs.settext('foo', 'bar')

And here is how you would read it back.

>>> from fs import open_fs
>>> with open_fs('zip://test.zip') as zip_fs:
...     print(zip_fs.gettext('foo'))
'bar'

A more typical use case would be to compress a directory, which you can do by opening a ZipFS for writing, and copying the files from another filesystem. Here's an example of one way you might compress the contents of a directory:

from fs.copy import copy_dir
copy_dir("~/projects", "zip://projects.zip")

See ZipFS docs for more information.

Author
Will McGugan
Published
Sep 1, 2017
Revision
2