← All notes

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

Sources

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

Permanent ID: iil:note:2qn2rftw

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.},
}

Markdown

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.

All artifact files (JSON index)

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.