Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

lzw

The lzw module wraps Go's compress/lzw package as whole-value operations. It deliberately does not expose Go readers and writers.

import "x/compress/lzw"

var compressed = lzw.compress("Goblin data")
print(lzw.decompress(compressed))
FunctionReturnsDescription
compress(data, order=lzw.LSB, lit_width=8, dest=unit)Bytes or unitCompress str or Bytes data
decompress(data, order=lzw.LSB, lit_width=8)BytesDecompress a complete LZW value

order is the lzw.LSB or lzw.MSB constant; lit_width must be from 2 through 8. Both options must match the format being read. Invalid compressed input raises ParseError.

Passing dest= streams the compressed output into any writer object — an object with a write(data) method, such as an open fs file — and compress then returns unit.