Golang compress/lzw.NewReader() function example
package compress/lzw
Golang compress/lzw.NewReader() function usage example. For decompressing LZW-compressed data.
package main
import (
"compress/lzw"
"fmt"
"io"
"os"
)
func main() {
inputFile, err := os.Open("file.txt.lzw")
if err != nil {
fmt.Println(err)
os.Exit(1)
}
defer inputFile.Close()
outputFile, err := os.Create("file.txt")
if err != nil {
fmt.Println(err)
os.Exit(1)
}
defer outputFile.Close()
// file.txt.lzw compressed by
// https://socketloop.com/references/golang-compress-lzw-newwriter-function-example
// litWidth is set to 8
lzwReader := lzw.NewReader(inputFile, lzw.LSB, 8) //<----- here !
if err != nil {
fmt.Println(err)
os.Exit(1)
}
defer lzwReader.Close()
io.Copy(outputFile, lzwReader)
}
Reference :
Advertisement
Something interesting
Tutorials
+7.3k Golang : How to check variable or object type during runtime?
+3.7k Mac OSX : Get disk partitions' size, type and name
+4.8k Linux : Disable and enable IPv4 forwarding
+7.3k Python : Fix SyntaxError: Non-ASCII character in file, but no encoding declared
+8.4k Golang : Get all countries currencies code in JSON format
+20.5k Golang : Use TLS version 1.2 and enforce server security configuration over client
+25.3k Golang : Force your program to run with root permissions
+29k Golang : Calculate percentage change of two values
+4.8k Golang : Error handling methods
+4.8k Golang : Denco multiplexer example
+32.9k Golang : Integer is between a range
+4.5k Golang : Frobnicate or tweaking a string example