feat: add --compression none for decompression support (#66)#78
feat: add --compression none for decompression support (#66)#78DhanashreePetare wants to merge 2 commits into
Conversation
|
Important Review skippedAuto reviews are disabled on base/target branches other than the default branch. Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
| # 'none' means no recompression after format conversion | ||
| final_compression = None if compression.lower() == "none" else compression |
There was a problem hiding this comment.
When a compressed file already matches the requested --format (for example file.ttl.bz2 --format ttl --compression none), the earlier same-format branch returns before reaching this new none guard and passes "none" into _convert_compression_format, which rejects it as an unsupported target format
databusclient download https://databus.dev.dbpedia.link/fhofer/gsoc26/test-data/v1.0/test-data_count=9.nq.bz2 --format nq --compression non
e
SPARQL endpoint https://databus.dev.dbpedia.link/sparql
Downloading file: https://databus.dev.dbpedia.link/fhofer/gsoc26/test-data/v1.0/test-data_count=9.nq.bz2
Local directory not given, using /home/fhofer/ddrive/dev/infai/dbpedia/databus-python-client/fhofer/gsoc26/test-data/v1.0
Download file: https://databus.dev.dbpedia.link/fhofer/gsoc26/test-data/v1.0/test-data_count=9.nq.bz2
Redirects url: https://raw.githubusercontent.com/Integer-Ctrl/gsoc-2026/refs/heads/main/test-data/sample.nq.bz2
100%|██████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████| 353/353 [00:00<00:00, 831kiB/s]
Error: Unsupported target compression format: none. Supported formats: ['bz2', 'gz', 'xz']
Result: test-data_count=9.nq.bz2 is downloaded
| def test_decompress_bz2_to_plain(): | ||
| """--compression none on bz2 file produces plain uncompressed file.""" | ||
| with tempfile.TemporaryDirectory() as tmpdir: | ||
| test_data = b"Decompression test data" * 50 | ||
|
|
||
| bz2_file = os.path.join(tmpdir, "test.txt.bz2") | ||
| with bz2.open(bz2_file, "wb") as f: | ||
| f.write(test_data) | ||
|
|
||
| plain_file = os.path.join(tmpdir, "test.txt") | ||
| with bz2.open(bz2_file, "rb") as sf: | ||
| with open(plain_file, "wb") as tf: | ||
| shutil.copyfileobj(sf, tf) | ||
| os.remove(bz2_file) | ||
|
|
||
| assert not os.path.exists(bz2_file) | ||
| assert os.path.exists(plain_file) | ||
| with open(plain_file, "rb") as f: | ||
| assert f.read() == test_data |
There was a problem hiding this comment.
Test seams useless. It only proves that Python’s bz2.open plus shutil.copyfileobj works, so it
would pass even if the actual implementation were broken. I would expect that a method is called for this, e.g. _convert_compression_format or whatever is responsible for this. Please refactor
Pull Request
Description
Adds --compression none as a valid value for the --compression flag, enabling users to decompress downloaded files without recompressing them to another format.
Previously, --compression only supported bz2, gz, and xz — meaning users could convert between compression formats or compress uncompressed files, but had no way to simply decompress a file and save it as-is. With this change, --compression none decompresses the file and saves it without any compression extension.
If the file is already uncompressed, --compression none is a no-op.
Related Issues
closes #66
Type of change
Checklist:
poetry run pytest- all tests passedpoetry run ruff check- no linting errors