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://', 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://') as zip_fs:
...     print(zip_fs.gettext('foo'))

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://")

See ZipFS docs for more information.

Will McGugan
Sep 1, 2017