Golang compress/zlib.NewReader() function example
package compress/zlib
Golang compress/zlib.NewReader() function usage example.
package main
import (
"compress/zlib"
"fmt"
"io"
"os"
)
func main() {
inputFile, err := os.Open("file.txt.zlib")
if err != nil {
fmt.Println(err)
os.Exit(1)
}
defer inputFile.Close()
outputFile, err := os.Create("file.txt")
if err != nil {
fmt.Println(err)
os.Exit(1)
}
defer outputFile.Close()
reader, _ := zlib.NewReader(inputFile) //<--- here!
if err != nil {
fmt.Println(err)
os.Exit(1)
}
defer reader.Close()
io.Copy(outputFile, reader)
}
References :
https://golang.org/pkg/compress/zlib/#NewReader
https://www.socketloop.com/tutorials/golang-decompress-zlib-file-example
Advertisement
Something interesting
Tutorials
+12.4k Golang : Query string with space symbol %20 in between
+7.2k Golang : Check if integer is power of four example
+8.5k Golang : Format strings to SEO friendly URL example
+11.6k Golang : Drop cookie to visitor's browser and http.SetCookie() example
+23.1k Golang : Time slice or date sort and reverse sort example
+9.8k Golang : Natural string sorting example
+19.9k Golang : How to get time zone and load different time zone?
+25.5k Golang : How to check if a connection to database is still alive ?
+48.7k Golang : Disable security check for HTTPS(SSL) with bad or expired certificate
+13.3k Golang : Parsing or breaking down URL
+7.1k Golang : Variadic function arguments sanity check example
+10.1k Golang : Find age or leap age from date of birth example