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
+18.7k Golang : convert int to string
+8.9k Golang : Gaussian blur on image and camera video feed examples
+5k Python : Convert(cast) bytes to string example
+6.5k Golang : Calculate diameter, circumference, area, sphere surface and volume
+27.2k Golang : Find files by name - cross platform example
+3.4k Golang : Fix go-cron set time not working issue
+8.8k Yum Error: no such table: packages
+5.2k Golang : Calculate half life decay example
+8.6k Golang : Convert(cast) []byte to io.Reader type
+9.7k Golang : Format strings to SEO friendly URL example
+5.6k Golang : Shortening import identifier
+36k Golang : Get file last modified date and time