The emptiest input is the sharpest test of a codec's edges. Today you pin that compressing nothing yields just a header, and decompressing it returns nothing - no crash, no phantom bytes.
Round-trip an empty input through Compress and Decompress.
Empty input is the boundary every codec must survive, and it exercises the whole
stack at zero size. Compress of nothing computes both encodings: the DEFLATE-lite
form still carries code tables and so is larger, meaning stored wins and the
output is just the seven-byte header with an original length of 0. Decompress
reads that length, runs no copy loop, and returns an empty slice.
The value here is in the guards. A decode loop that assumes at least one symbol, or
a table reader that assumes at least one entry, will happily crash on empty input
unless you check for the zero case. Pinning Decompress(Compress(empty)) == empty
forces those guards into place. It is a small spec with an outsized payoff: the
same “handle zero gracefully” discipline is what keeps the tool from panicking on
truncated or degenerate files, which is exactly where the next lesson goes.
// empty input: original length 0. deflate would still emit code tables,// so stored (7 bytes) wins and Compress returns just the header.// Decompress reads length 0 and returns an empty slice - guard the// loops so "no symbols" and "no payload" do not panic.if len(data) == 0 { /* stored path yields header only */ }