Golang compress/lzw.NewWriter() function example
package compress/lzw
Golang compress/lzw.NewWriter() function usage example. For compressing data with LZW algorithm.
package main
import (
"compress/lzw"
"fmt"
"io"
"os"
)
func main() {
inputFile, err := os.Open("file.txt")
if err != nil {
fmt.Println(err)
os.Exit(1)
}
defer inputFile.Close()
outputFile, err := os.Create("file.txt.lzw")
if err != nil {
fmt.Println(err)
os.Exit(1)
}
defer outputFile.Close()
// The number of bits to use for literal codes, litWidth, must be in the
// range [2,8] and is typically 8.
lzwWriter := lzw.NewWriter(outputFile, lzw.LSB, 8) // <---- here !
if err != nil {
fmt.Println("NewWriter error ", err)
os.Exit(1)
}
defer lzwWriter.Close()
io.Copy(lzwWriter, inputFile)
}
Reference :
Advertisement
Something interesting
Tutorials
+7.8k Javascript : How to check a browser's Do Not Track status?
+8.3k Your page has meta tags in the body instead of the head
+9.8k Golang : ffmpeg with os/exec.Command() returns non-zero status
+7.3k Golang : Calculate how many weeks left to go in a given year
+12.9k Golang : Get terminal width and height example
+18.4k Golang : Example for RSA package functions
+28.4k Golang : Change a file last modified date and time
+7.4k Golang : Process json data with Jason package
+5.8k Golang : Use NLP to get sentences for each paragraph example
+8.3k Golang: Prevent over writing file with md5 hash
+31.3k Golang : bufio.NewReader.ReadLine to read file line by line
+6.6k Golang : Reverse by word