Go compress/lzw: Lempel-Ziv-Welch compressed data
Answer: Package lzw implements the Lempel-Ziv-Welch compressed data format.
Where this format appears
The package follows the Welch paper on high-performance data compression.
In particular it implements LZW as used in GIF and PDF file formats.
The TIFF file format uses a similar but incompatible version of the LZW algorithm.
A separate image tiff lzw package provides a TIFF implementation.
Readers, writers, and bit order
It is the caller's responsibility to call Close when finished reading.
The litWidth for literal codes must be in the range 2 to 8 and is typically 8.
Order specifies the bit ordering in an LZW data stream.
LSB means Least Significant Bits first, as used in the GIF file format, while MSB is used in TIFF and PDF.
See also
Claims
- id: C1 claim: Package lzw implements the Lempel-Ziv-Welch compressed data format. source: S1 evidence: "Package lzw implements the Lempel-Ziv-Welch compressed data format"
- id: C2 claim: TIFF uses a similar but incompatible version of the LZW algorithm. source: S1 evidence: "similar but incompatible version of the LZW"
- id: C3 claim: Order specifies the bit ordering in an LZW data stream. source: S2 evidence: "Order specifies the bit ordering in an LZW data stream"
- id: C4 claim: LSB means Least Significant Bits first, as used in GIF. source: S2 evidence: "LSB means Least Significant Bits first, as used in the GIF"
Sources
- [S1] lzw package reference. The Go Authors. https://pkg.go.dev/compress/lzw . License: BSD-3-Clause. Accessed 2026-11-24.
- [S2] lzw reader.go source. The Go Authors. https://go.dev/src/compress/lzw/reader.go . License: BSD-3-Clause. Accessed 2026-11-24.
License: this note is CC BY 4.0 (https://creativecommons.org/licenses/by/4.0/). Summary by iinventedlight (AI-assisted). Sources: The Go Authors, lzw package reference; The Go Authors, lzw reader.go source. BSD-3-Clause (https://go.dev/LICENSE). Copyright The Go Authors. Text was condensed and changed from the originals.
License: CC-BY-4.0 · Summary by iinventedlight (AI-assisted). Sources: The Go Authors, lzw package reference; The Go Authors, lzw reader.go source. BSD-3-Clause (https://go.dev/LICENSE). Copyright The Go Authors.
Cite this
iinventedlight. 2026. "Go compress/lzw: Lempel-Ziv-Welch compressed data." iinventedlight Library, iil:note:2qn2rftw, version of 2026-11-24. https://iinventedlight.com/library/notes/go-lzw/. License: CC-BY-4.0.
@misc{iil_note_2qn2rftw,
author = {{iinventedlight}},
title = {{Go compress/lzw: Lempel-Ziv-Welch compressed data}},
howpublished = {iinventedlight Library},
year = {2026},
date = {2026-11-24},
url = {https://iinventedlight.com/library/notes/go-lzw/},
note = {Permanent ID iil:note:2qn2rftw. License: CC-BY-4.0.},
}
Spotted a mistake? Use the MCP feedback tool or email hello@iinventedlight.com. Or Report a correction (no account needed).
Extra files beside this note
These files use this note's license, shown below. Paper extras retain their reproduction status; a link is not a reproduction.
- go-lzw.schema.json (schema; CC-BY-4.0)
- go-lzw.table.json (table; CC-BY-4.0)
For language models and agents: start at /llms.txt | /agents.md | /.well-known/agent-library.json. This page in Markdown: /library/notes/go-lzw.md.