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
+10.8k Android Studio : Checkbox for user to select options example
+6.5k Elasticsearch : Shutdown a local node
+14.6k Golang : Send email with attachment(RFC2822) using Gmail API example
+12.1k Golang : convert(cast) string to integer value
+12.7k Golang : Remove or trim extra comma from CSV
+22.1k Golang : Repeat a character by multiple of x factor
+5.8k Javascript : How to replace HTML inside <div>?
+14.9k Golang : Basic authentication with .htpasswd file
+17.2k Golang : When to use init() function?
+4.6k MariaDB/MySQL : How to get version information
+23.5k Golang : Read a file into an array or slice example
+17k Golang : Get input from keyboard