Skip to content

Instantly share code, notes, and snippets.

@oldpatricka
Created November 2, 2018 20:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save oldpatricka/bad8cd8bc6d13d58e7b140990e2081fd to your computer and use it in GitHub Desktop.
Save oldpatricka/bad8cd8bc6d13d58e7b140990e2081fd to your computer and use it in GitHub Desktop.
Simple program to decompress TIFF-flavoured LZW compressed files
package main
// To run, first install image/tiff/lzw with:
// go get golang.org/x/image/tiff/lzw
// Then run like `cat my.lzw | go run tiff-lzw.go`
import (
"bufio"
"fmt"
"golang.org/x/image/tiff/lzw"
"io/ioutil"
"os"
)
func main() {
// Read and decompress LZW Bytes from stdin
lzwReader := lzw.NewReader(os.Stdin, lzw.MSB, 8)
b, err := ioutil.ReadAll(lzwReader)
if err != nil {
panic(err)
}
// Write decompressed Bytes to stdout
w := bufio.NewWriter(os.Stdout)
n, err := w.Write(b)
if err != nil {
panic(err)
}
w.Flush()
// Print summary
fmt.Fprintf(os.Stderr, "%d bytes decompressed\n", n)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment