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
+11k Golang : Create S3 bucket with official aws-sdk-go package
+4.7k JavaScript: Add marker function on Google Map
+5.6k Swift : Get substring with rangeOfString() function example
+12.5k Golang : "https://" not allowed in import path
+20.4k nginx: [emerg] unknown directive "passenger_enabled"
+22.1k Golang : Match strings by wildcard patterns with filepath.Match() function
+8.2k Prevent Write failed: Broken pipe problem during ssh session with screen command
+12.9k Python : Convert IPv6 address to decimal and back to IPv6
+6.8k Golang : Join lines with certain suffix symbol example
+14.6k Golang : Convert(cast) int to float example
+10.4k Golang : Simple Jawi(Yawi) to Rumi(Latin/Romanize) converter
+14.4k Golang : How to convert a number to words