Open an RFC 1950 Zlib Stream with Python
Admin ·
Use zlib when a consumer expects a DEFLATE payload with the RFC 1950 header and Adler-32 checksum. The tool can compress text as UTF-8 or preserve the exact bytes of a selected file.
Verify all 832 input bytes after decompression
Select Load worked example and keep level 6. The text contains 64 copies of Sensor écho followed by a line feed. Each copy takes 13 UTF-8 bytes because é takes two bytes. Compress and confirm that Input bytes is 832 B.
Download text.zlib. This Python example decompresses the stream and confirms the exact bytes and the checksum stored in its four-byte trailer.
from pathlib import Path
import zlib
stream = Path('text.zlib').read_bytes()
plain = zlib.decompress(stream)
assert plain == ('Sensor écho\n' * 64).encode('utf-8')
assert int.from_bytes(stream[-4:], 'big') == zlib.adler32(plain)Open the Zlib CompressorRFC 1950 ZLIB Compressed Data FormatPython zlib decompression and checksum documentation
Compare Base64, hex and the binary download
Choose Base64, then Hex. They encode the same compressed bytes. Python’s base64.b64decode can convert copied Base64 back to bytes. bytes.fromhex can do the same for the hex output. Both should equal the binary download.
The text preview stops after 1,536 compressed bytes. Choose Prepare full encoding if you need the complete encoded file. Download .zlib always saves the full binary stream.
Open the Zlib CompressorRFC 1950 ZLIB Compressed Data Format
Match the wrapper expected by your decoder
Python zlib.decompress(data) expects the zlib format by default. A decoder configured with wbits=-15 expects raw DEFLATE, while a gzip reader expects a different header and checksum. Check the receiving format before choosing a tool.
Level zero still writes a zlib stream with stored blocks. A tiny or already compressed input can be larger after compression. Use the measured byte counts to compare outputs.
Python zlib decompression and checksum documentationRFC 1950 ZLIB Compressed Data FormatRFC 1951 DEFLATE Compressed Data Format
Common questions
Does a .zlib stream preserve the filename?
The format carries one compressed byte sequence and an integrity checksum. The original filename can be recorded separately if the receiver needs it.
How can I preserve an original file’s BOM or line endings?
Select Exact file bytes and open the file. Text mode encodes the editor contents as UTF-8, while file mode compresses the bytes as supplied.
Will every compressor produce byte-identical output?
Compressors can choose different valid DEFLATE blocks. Verify that decompression restores the original bytes and that the receiving software accepts the required wrapper.