Golang compress/flate.NewReader() and NewReaderDict() functions example
package compress/flate
Golang compress/flate.NewReader() and NewReaderDict() functions usage example.
package main
import (
"compress/flate"
"fmt"
"io"
"os"
)
func main() {
inputFile, err := os.Open("file.txt.compressed")
if err != nil {
fmt.Println(err)
os.Exit(1)
}
defer inputFile.Close()
outputFile, err := os.Create("file.txt.decompressed")
if err != nil {
fmt.Println(err)
os.Exit(1)
}
defer outputFile.Close()
flateReader := flate.NewReader(inputFile) //<----- here!
defer flateReader.Close()
io.Copy(outputFile, flateReader)
}
and if the file is compressed with NewWriterDict ( with Dictionary ), use NewReaderDict() function instead :
// note : NewReaderDict is typically used to read data compressed by NewWriterDict.
var dict = "test files for Golang"
flateReader := flate.NewReaderDict(inputFile, []byte(dict))
References :
Advertisement
Something interesting
Tutorials
+7.9k Golang : Find the length of big.Int variable example
+13.1k Golang : Find network of an IP address
+10.7k Golang : Split strings into command line arguments
+15.1k Golang : Test floating point numbers not-a-number and infinite example
+4k HTTP common errors and their meaning explained
+8.4k Golang : Convert(cast) string to int64
+8k Golang : Generate random Chinese, Japanese, Korean and other runes
+25k Golang : Convert file content into array of bytes
+18.6k Android Studio : AlertDialog and EditText to get user string input example
+8.4k Golang : ffmpeg with os/exec.Command() returns non-zero status
+4.8k Unix/Linux : How to open tar.gz file ?