This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: bz2: BZ2File should expose compression level as an attribute
Type: enhancement Stage: needs patch
Components: Library (Lib) Versions: Python 3.6
process
Status: open Resolution:
Dependencies: Superseder:
Assigned To: Nosy List: joshtriplett, martin.panter, r.david.murray, xiang.zhang
Priority: normal Keywords:

Created on 2016-07-04 20:01 by joshtriplett, last changed 2022-04-11 14:58 by admin.

Messages (5)
msg269806 - (view) Author: Josh Triplett (joshtriplett) Date: 2016-07-04 20:01
(This exists in both Python 3 and Python 2.)

When opening an existing .bz2 file with BZ2File, I'd like to have access to the compression level, so that I don't have to manually parse the file's header to get it.  BZ2File could provide the compression level as an attribute on itself.
msg269818 - (view) Author: R. David Murray (r.david.murray) * (Python committer) Date: 2016-07-05 11:38
New features can only be added in a new feature release, which means 3.6 at the moment (the window for that is shrinking fast, though, we hit beta in September).
msg272756 - (view) Author: Xiang Zhang (xiang.zhang) * (Python committer) Date: 2016-08-15 13:14
If you don't want to manually parse it, the lib has to. Currently, bz2 delegates all the raw data parsing (compression/decompression) to the underlying C library. Unfortunately the bzip2 library doesn't expose the header info which means to get compression level, we have to do some raw data parsing in the lib.

Actually I wonder if it's worth though this seems not hard to implement.
msg274348 - (view) Author: Martin Panter (martin.panter) * (Python committer) Date: 2016-09-04 07:26
I guess the compression level you want is the same as the 100–900 kB block size recorded as the third byte in the header.

But I don’t see this as a particularly useful feature either. Why do you want to know the compression level?
msg274349 - (view) Author: Josh Triplett (joshtriplett) Date: 2016-09-04 08:33
As part of a reproducible build project, to allow recompressing a file with the same compression level previously used.
History
Date User Action Args
2022-04-11 14:58:33adminsetgithub: 71637
2016-09-04 08:33:02joshtriplettsetmessages: + msg274349
2016-09-04 07:26:19martin.pantersetmessages: + msg274348
2016-08-15 13:14:01xiang.zhangsetnosy: + xiang.zhang, martin.panter
messages: + msg272756
2016-07-05 11:38:43r.david.murraysetversions: - Python 2.7, Python 3.5
nosy: + r.david.murray

messages: + msg269818

stage: needs patch
2016-07-04 20:01:33joshtriplettcreate