Golang compress/gzip.NewReader() function example
package compress/gzip
Golang compress/gzip.NewReader() function usage example.
package main
import (
"compress/gzip"
"fmt"
"io"
"os"
)
func main() {
inputFile, err := os.Open("file.txt.gz")
if err != nil {
fmt.Println(err)
os.Exit(1)
}
defer inputFile.Close()
outputFile, err := os.Create("file.txt.unzipped")
if err != nil {
fmt.Println(err)
os.Exit(1)
}
defer outputFile.Close()
reader, _ := gzip.NewReader(inputFile) //<--- here!
if err != nil {
fmt.Println(err)
os.Exit(1)
}
defer reader.Close()
io.Copy(outputFile, reader)
}
References :
Advertisement
Something interesting
Tutorials
+14.1k Golang : Validate hostname
+50.1k Golang : Check if item is in slice/array
+6.3k Golang : Check to see if *File is a file or directory
+3.9k MariaDB/MySQL : Form select statement or search query with Chinese characters
+31.3k Golang : Smarter Error Handling with strings.Contains()
+4.9k Golang : Launching your executable inside a console under Linux
+8.4k Golang : Accessing content anonymously with Tor
+18.5k Golang : Append content to a file
+10k Golang : Fix fmt.Scanf() on Windows will scan input twice problem
+14.7k Golang : Read a file line by line
+9.4k Golang : Select region of interest with mouse click and crop from image