fs.compress

Functions to compress the contents of a filesystem.

Currently zip and tar are supported, using the zipfile and tarfile modules from the standard library.

fs.compress.write_tar(src_fs, file, compression=None, encoding=u'utf-8', walker=None)[source]

Write the contents of a filesystem to a tar file.

Parameters:
  • file (str or io.IOBase) – Destination file, may be a file name or an open file object.
  • compression (str, optional) – Compression to use, or None for a plain Tar archive without compression.
  • encoding (str) – The encoding to use for filenames. The default is "utf-8".
  • walker (Walker, optional) – A Walker instance, or None to use default walker. You can use this to specify which files you want to compress.
fs.compress.write_zip(src_fs, file, compression=8, encoding=u'utf-8', walker=None)[source]

Write the contents of a filesystem to a zip file.

Parameters:
  • src_fs (FS) – The source filesystem to compress.
  • file (str or io.IOBase) – Destination file, may be a file name or an open file object.
  • compression (int) – Compression to use (one of the constants defined in the zipfile module in the stdlib). Defaults to zipfile.ZIP_DEFLATED.
  • encoding (str) – The encoding to use for filenames. The default is "utf-8", use "CP437" if compatibility with WinZip is desired.
  • walker (Walker, optional) – A Walker instance, or None to use default walker. You can use this to specify which files you want to compress.