https://github.com/karlicoss/kompress
Helper to allow accessing compressed files/directories via pathlib.Path
https://github.com/karlicoss/kompress
Last synced: 9 months ago
JSON representation
Helper to allow accessing compressed files/directories via pathlib.Path
- Host: GitHub
- URL: https://github.com/karlicoss/kompress
- Owner: karlicoss
- License: mit
- Created: 2023-10-02T22:58:53.000Z (over 2 years ago)
- Default Branch: master
- Last Pushed: 2025-02-05T23:50:01.000Z (11 months ago)
- Last Synced: 2025-04-02T20:05:08.680Z (9 months ago)
- Language: Python
- Size: 47.9 KB
- Stars: 4
- Watchers: 2
- Forks: 1
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
`kompress` lets you transparently decompress common archive formats while using `pathlib.Path` objects.
It attempts to keep the API as close to pathlib, but things may not be perfect yet
The common case for this is:
- You have a compressed file that when decompressed contains some text
- You have a function (perhaps from another library, that you don't control), that knows how to take a `pathlib.Path` object and call `.read()` or `.read_text()` on it
Without wrapping the function or adding logic to let it read from compressed files, this lets you do the following:
```python
from pathlib import Path
from kompress import CPath, is_compressed
def char_count(path: Path) -> int:
# here, if a CPath is passed, it decompresses and returns a string
return len(path.read_text())
inp = input("Enter a file to process: ") # file came from user
char_count(CPath(inp))
```
This currently supports these archive formats:
- `.xz`
- `.zip`
- `.lz4` (`pip install 'kompress[lz4]'`)
- `.zstd` (`pip install 'kompress[zstd]'`)
- `.zst`
- `.tar.gz`
- `.gz`
If it doesn't recognize the filetype, it will just call `pathlib.Path.open` like normal
Originally discussed in this [HPI issue](https://github.com/karlicoss/HPI/issues/20)
## Installing
`pip install kompress`