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
+9.1k Golang : Handle sub domain with Gin
+8.7k Golang : How to join strings?
+6.7k Golang : Reverse by word
+10.5k Swift : Convert (cast) String to Integer
+5.8k Linux : Disable and enable IPv4 forwarding
+5.5k Golang : Stop goroutine without channel
+8.8k Android Studio : Image button and button example
+16.3k Golang : How to extract links from web page ?
+6.5k Golang : Map within a map example
+14k Golang : Reverse IP address for reverse DNS lookup example
+11k How to test Facebook App on localhost ?
+23.7k Find and replace a character in a string in Go