Standard library / compress/lzw

compress/lzw.Order

Enumeration controlling the packing of variable-width LZW codes, not integer byte endianness. LSB and MSB streams are not interchangeable. Go uses GIF/PDF-style LZW, not the incompatible TIFF variant. Expected stdout: 'Go Go\n'.

Formal Syntax & Structure

go syntaxgo
type Order int

Working Example

Example Snippetgo
package main
import (  "bytes"  "compress/lzw"  "fmt"  "io")
func must(e error) {  if e != nil {    panic(e)  }}func pack(s string, order lzw.Order) []byte {  var b bytes.Buffer  w := lzw.NewWriter(&b, order, 8)  _, e := w.Write([]byte(s))  must(e)  must(w.Close())  return b.Bytes()}func unpack(b []byte, order lzw.Order) string {  r := lzw.NewReader(bytes.NewReader(b), order, 8)  p, e := io.ReadAll(r)  must(e)  must(r.Close())  return string(p)}func main() { fmt.Println(unpack(pack("Go", lzw.LSB), lzw.LSB), unpack(pack("Go", lzw.MSB), lzw.MSB)) }
Go Reference