Created
November 2, 2018 20:32
-
-
Save oldpatricka/bad8cd8bc6d13d58e7b140990e2081fd to your computer and use it in GitHub Desktop.
Simple program to decompress TIFF-flavoured LZW compressed files
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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