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
+12.8k Swift : Convert (cast) Int or int32 value to CGFloat
+10.3k Golang : Detect number of faces or vehicles in a photo
+11.2k Golang : Fix - does not implement sort.Interface (missing Len method)
+9.9k Golang : ffmpeg with os/exec.Command() returns non-zero status
+4.7k PHP : Extract part of a string starting from the middle
+29.2k Golang : missing Git command
+4.4k Linux/MacOSX : Search and delete files by extension
+17.2k Golang : Find file size(disk usage) with filepath.Walk
+17k Golang : XML to JSON example
+9.2k Golang : How to find out similarity between two strings with Jaro-Winkler Distance?
+9.4k Golang : Scramble and unscramble text message by randomly replacing words
+16.9k Golang : How to generate QR codes?