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
+5k Python : Convert(cast) bytes to string example
+12k Golang : How to parse plain email text and process email header?
+9.7k Golang : Sort and reverse sort a slice of floats
+8.9k Golang : Take screen shot of browser with JQuery example
+21.9k SSL : How to check if current certificate is sha1 or sha2
+9k Golang : Populate or initialize struct with values example
+31k Golang : Interpolating or substituting variables in string examples
+7.2k Golang : A simple forex opportunities scanner
+8.6k Linux/Unix : fatal: the Postfix mail system is already running
+7.8k Golang : Test if an input is an Armstrong number example