class composer.utils.CliCompressor(extension, cmd=None)[source]#

Base class for data compression CLI tools.

This class handles compression and decompression of data by piping it through CLI compressor tools installed on the system. e.g. the gzip command for producing .gz files.

Example: .. code-block:: python

compressor = CliCompressor(โ€˜gzโ€™, โ€˜gzipโ€™)

with compressor.compress(โ€˜myfile.txt.gzโ€™) as f:


with compressor.decompress(โ€˜myfile.txt.gzโ€™) as f:

assert == โ€˜fooโ€™

  • extension (str) โ€“ The suffix used to identify files that the compressor supports (without a leading .).

  • cmd (str, optional) โ€“ The name of the CLI tool that this compressor uses. Defaults to None, in which case it is assumed that the tool name is the same as the extension.


Compress some data, saving to the given file.


Decompress the content of the given file, providing the output as a file-like object.

property exists#

Whether the CLI tool used by this compressor can be found.