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 Golang : Create S3 bucket with official aws-sdk-go package
+7.2k Golang : Handling Yes No Quit query input
+14.6k Golang : Submit web forms without browser by http.PostForm example
+24.7k Golang : Create PDF file from HTML file
+7.9k Golang : Randomize letters from a string example
+17.3k Golang : Upload/Receive file progress indicator
+15.9k Golang : convert string or integer to big.Int type
+28.8k Golang : Saving(serializing) and reading file with GOB
+6.5k Default cipher that OpenSSL used to encrypt a PEM file
+20k Android Studio : AlertDialog and EditText to get user string input example
+9.9k Golang : Detect number of faces or vehicles in a photo
+13.5k Golang : Get dimension(width and height) of image file