compfile Common interfaces for manipulating compressed files (lzma, gzip etc)
Rationale
Sometimes, we need to deal with different compressed files. There are several packages/modules for compressed file manipulation, e.g., gzip module for "*.gz" files, lzma module for "*.lzma" and "*.xz" files, etc. If we want to support different types of compressed file in our project, probably we need to do the following:
if fnmatch.fnmatch(fname, "*.gz"):
f = gzip.open(fname, 'rb')
# do something with f
elif fnmatch.fnmatch(fname, "*.bz2'):
f = bz2.open(fname, 'rb')
# do something with f
else:
# other stuffs
The problems of the above approch are:
- We need to repeat the compression type inference logic everywhere we want to support different compression types.
- Different compression type manipulation modules may have different API convention.
compfile is designed to solve the above problems. It abstracts the logic of compressed file manipulations and provides a single high level interface for users.
Installation
Install from PyPI
pip install compfile
Install from Anaconda
conda install -c liyugong compfile
Install from GitHub
pip install git+https://github.com/gongliyu/compfile.git@master
Simple example
Using compfile is pretty simple. Just construct a compfile.CompFile object or call compfile.open
with compfile.open(fname, 'r') as f:
# do something with f
The object returned is a file object, so we can do ordinary file processing with it.
License
The compfile package is released under the MIT License
Documentation
Release files for compfile 0.0.3
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| compfile-0.0.3.tar.gz | 5.0 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| compfile-0.0.3-py2.py3-none-any.whl | Python 2, Python 3 | none | any | Details |
Total release size: 8.9 kB
Release files / compfile-0.0.3.tar.gz
| Download URL | compfile-0.0.3.tar.gz |
|---|---|
| Size | 5.0 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
d620f539904ab8e72d97d73065211824113999d82ba20acd9d097d2a1a3358ac
|
|
BLAKE2b-256 checksum How to use checksums |
24be5e7717ea7f99703d2fa451715068fef5de9a068ef1a00c5d03d782d7ef62
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/1.12.1 pkginfo/1.4.2 requests/2.19.1 setuptools/40.2.0 requests-toolbelt/0.8.0 tqdm/4.26.0 CPython/3.6.6
|
Release files / compfile-0.0.3-py2.py3-none-any.whl
| Download URL | compfile-0.0.3-py2.py3-none-any.whl |
|---|---|
| Size | 3.9 kB |
| Tags | Python 2 Python 3 |
|
SHA-256 checksum How to use checksums |
79fc36935475551a7002693ab88093daf9751be436a01166976d4d8422f9860b
|
|
BLAKE2b-256 checksum How to use checksums |
3ab197389fbc3077b332623afa9af70ee38a65fc8d7341a757c3a18254aa655f
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/1.12.1 pkginfo/1.4.2 requests/2.19.1 setuptools/40.2.0 requests-toolbelt/0.8.0 tqdm/4.26.0 CPython/3.6.6
|