Library:Bzip2
Appearance
| Developer | Julian Seward |
|---|---|
| Platforms | any (portable C) |
| Versions | 1.0.8 (13-Jul-2019) is the latest tagged release |
| License | bzip2 license (BSD-style) |
| Website | https://sourceware.org/bzip2/ |
| On this wiki | Facts · Code · Notes · Topics |
The reference bzip2 compression library libbz2 (C, BSD-style license, Julian Seward, 1.0.8 in 2019): BZ2_bz* API, a version string, and a big-endian CRC-32 table that identify it in a binary.
Overview
libbz2 is statically linked or shipped as libbz2.so.1.0 / libbz2.dll / bz2.dll (Python's _bz2 module, 7-Zip-like tools, game archives, firmware images). It reads and writes Format:Bzip2.
Identification
- Exported names all start
BZ2_bz: BZ2_bzCompressInit, BZ2_bzCompress, BZ2_bzCompressEnd, BZ2_bzDecompressInit, BZ2_bzDecompress, BZ2_bzDecompressEnd, BZ2_bzReadOpen, BZ2_bzWriteOpen, BZ2_bzBuffToBuffCompress, BZ2_bzBuffToBuffDecompress, BZ2_bzlibVersion (list in libbz2.def). - Version string returned by BZ2_bzlibVersion:
1.0.8, 13-Jul-2019(BZ_VERSION in bzlib_private.h). Older builds carry e.g.1.0.6, 6-Sept-2010. Release builds usually keep it as a plain string. - Constant table
BZ2_crc32Table[256]: MSB-first CRC-32, first words00000000 04C11DB7 09823B6E 0D4326D9(stored in the byte order of the target CPU). - Other tables in the data:
BZ2_rNums[512](randomisation table, starts 619 720 127 481 931 816 813 233 566 247) andBZ2_hbCreateDecodeTables-related code; the sort uses a fixed increments table1, 4, 13, 40, 121, 364, 1093, 3280, .... - Compiled code compares bytes against 0x31 0x41 0x59 0x26 0x53 0x59 and 0x17 (decompress.c) or writes them one by one (compress.c).
- Limits that show up as immediates: BZ_N_GROUPS 6, BZ_MAX_CODE_LEN 23, BZ_G_SIZE 50, BZ_MAX_SELECTORS 18002.
Pitfalls
- Forks (Apple, Python bundled copy, 7-Zip's own implementation, libbzip3) keep the format but not necessarily the strings. 7-Zip uses its own C++ decoder and does not export BZ2_*.
- BZ2_rNums and the sort increments table were read in randtable.c and blocksort.c of the pinned commit.
Code & repositories
See the linked repository.
- https://github.com/libarchive/bzip2 @
1ea1ac188ad4b9cb662e3f8314673c63df95a589· license: bzip2-1.0.6 (declared by the contributor; GitHub's detector did not recognize COPYING)
GitHub mirror of the reference bzip2 source (1.0.8)
Tested on: source read, not run: source only · checked 2026-10-18; last activity 2022-04-08
Open questions
- Which bzip2 versions carry which BZ_VERSION string (0.9.5, 1.0.0 to 1.0.8)?