Compression

class chepy.modules.compression.Compression(*data)
bzip_compress() CompressionT

Compress the state into bz2 archive

Returns

The Chepy object.

Return type

Chepy

Examples

>>> c = Chepy("some data").bzip_compress()
b'BZh91AY&SY\x9f\xe2\xaa\x9d\x00\x00\x03...

We can now write this as a bz2 file with >>> c.write(“/path/to/file.bz2”, as_binary=True)

bzip_decompress() CompressionT

Decompress a bz2 archive

Returns

The Chepy object.

Return type

Chepy

create_zip_file(file_name: str) CompressionT

Create a zip archive with data from state

Parameters

file_name (str) – File name for file inside zip archive

Returns

The Chepy object.

Return type

Chepy

Examples

>>> c = Chepy("some data").create_zip_file()
>>> c.write("/some/path/file.zip", as_binary=True)
fix_zip_header() CompressionT

Fix the first 4 bytes of a zip file

Returns

The Chepy object.

Return type

Chepy

gzip_compress(file_name: str = None) CompressionT

Create a gz archive with data from state

Parameters

file_name (str, optional) – File name for file inside zip archive. Defaults to None.

Returns

The Chepy object.

Return type

Chepy

Examples

>>> c = Chepy("some data").gzip_compress()
>>> c.write("/some/path/file.zip", as_binary=True)
gzip_decompress() CompressionT

Decompress a gzip archive

Returns

The Chepy object.

Return type

Chepy

lz4_compress() CompressionT

LZ4 compress

Returns

The Chepy object.

Return type

Chepy

lz4_decompress() CompressionT

LZ4 decompress

Returns

The Chepy object.

Return type

Chepy

lz77_compress(window_size: int = 13, lookahead_buffer_size: int = 6)

To LZ77 compression

Parameters
  • window_size (int, optional) – Window size. Defaults to 13.

  • lookahead_buffer_size (int, optional) – Lookahead. Defaults to 6.

Returns

The Chepy object.

Return type

Chepy

lz77_decompress(window_size: int = 13, lookahead_buffer_size: int = 6)

From LZ77 compression

Parameters
  • window_size (int, optional) – Window size. Defaults to 13.

  • lookahead_buffer_size (int, optional) – Lookahead. Defaults to 6.

Returns

The Chepy object.

Return type

Chepy

lzma_compress() CompressionT

Compress using xz lzma

Returns

The Chepy object.

Return type

Chepy

lzma_decompress() CompressionT

Decompress lzma compressed data

Returns

The Chepy object.

Return type

Chepy

raw_deflate() CompressionT

Raw deflate data

Returns

The Chepy object.

Return type

Chepy

raw_inflate() CompressionT

Raw inflate data

Returns

The Chepy object.

Return type

Chepy

tar_compress(filename: str, mode: str = 'gz') CompressionT

Compress the state into a tar compressed object.

Parameters
  • filename (str) – A file name for the tar object

  • mode (str, optional) – Compression mode. Defaults to “gz”.

Returns

The Chepy object.

Return type

Chepy

tar_extract_all(mode: str = '') CompressionT

Extract one file from inside a tar archive

Parameters

mode (str, optional) – Mode to open tar file as. Defaults to “”.

Returns

The Chepy object.

Return type

Chepy

tar_extract_one(filename: str, mode: str = '') CompressionT

Extract one file from inside a tar archive

Parameters
  • filename (str) – Required. File name inside archive.

  • mode (str, optional) – Mode to open tar file as. Defaults to “”.

Returns

The Chepy object.

Return type

Chepy

tar_list_files(mode: str = '') CompressionT

Get file information inside a tar archive

Parameters

mode (str, optional) – Mode to open tar file as. Defaults to “”.

Returns

The Chepy object.

Return type

Chepy

unzip_all(password: str = None) CompressionT

Unzip all files from zipfile into the state

Parameters

password (str, optional) – Password if zip is encrypted. Defaults to None.

Returns

The Chepy object.

Return type

Chepy

Examples

>>> c = Chepy("/path/to/zip.zip").load_file()
>>> c.unzip_all()
[b"Hello World!", b"haha"]
unzip_one(file: str, password: str = None) CompressionT

Unzip one file from zipfile

Use zip_list_files to get all the filenames within the zip archive

Parameters
  • file (str) – Required. Path of file inside the archive

  • password (str, optional) – Password if zip is encrypted. Defaults to None.

Returns

The Chepy object.

Return type

Chepy

Examples

>>> c = Chepy("/path/to/zip.zip").load_file()
>>> c.zip_info()
['somefile.txt', 'some_dir/some_file'...]
>>> c.unzip_one("somefile.txt")
b"Hello World!"
zip_compress(file_name: str) CompressionT

Compress the state as a zipfile

Parameters

filename (str) – File name

Returns

The Chepy object.

Return type

Chepy

Create a zipfile with a symlink pointer. For unix

Parameters
  • filename (str) – File name

  • target_file (str) – Target system file

Returns

The Chepy object.

Return type

Chepy

zip_info() CompressionT

Gets various information about a zip file

This includes information about all the files inside the archive.

Returns

The Chepy object.

Return type

Chepy

Examples

>>> c = Chepy("/path/to/example.zip")
>>> c.load_file().zip_info()
[{'CRC': 1779821815, '_compresslevel': None, '_raw_time': 19712,...}]
zip_list_files() CompressionT

Get a list of files inside the zip archive

Returns

The Chepy object.

Return type

Chepy

Examples

>>> Chepy("some.zip").load_file().zip_list_files().o
['somefile', 'some_dir/some_file'...]
zlib_compress(level: int = 9) CompressionT

Compress using zlib

Parameters

level (int, optional) – Level of compression. 0-9. Defaults to 9.

Returns

The Chepy object.

Return type

Chepy

Examples

>>> Chepy("some text").zlib_compress().to_hex().o
b"78da2bcecf4d552849ad28010011e8039a"
zlib_decompress() CompressionT

Zlib decompression

Returns

The Chepy object.

Return type

Chepy

Examples

>>> c = Chepy("789c0580a10d000008c35ee1b9ca05c104e737b761ca5711e8039a")
>>> c.hex_to_bytes()
>>> c.zlib_decompress()
>>> c.out
b"some text"