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
+8.2k Golang : Qt splash screen with delay example
+16.6k Golang : Generate QR codes for Google Authenticator App and fix "Cannot interpret QR code" error
+11.2k Golang : How to pipe input data to executing child process?
+9k Golang : Build and compile multiple source files
+22.8k Golang : untar or extract tar ball archive example
+13.6k Android Studio : Password input and reveal password example
+5.4k Golang : fmt.Println prints out empty data from struct
+16.3k Golang : Find out mime type from bytes in buffer
+10k Golang : Channels and buffered channels examples
+7.4k Golang : Word limiter example
+13.4k Golang : Verify token from Google Authenticator App
+10.6k Golang : Flip coin example