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
+6k PHP : How to check if an array is empty ?
+5.8k Unix/Linux : Get reboot history or check when was the last reboot date
+10.2k Golang : Text file editor (accept input from screen and save to file)
+18.6k Golang : Iterating Elements Over A List
+48.1k Golang : How to convert JSON string to map and slice
+8.8k Golang : Random integer with rand.Seed() within a given range
+16.9k Golang : Get the IPv4 and IPv6 addresses for a specific network interface
+7.8k Golang : Getting Echo framework StartAutoTLS to work
+9.1k Golang : Serving HTTP and Websocket from different ports in a program example
+18.7k Golang : convert int to string
+10.1k Golang : Check a web page existence with HEAD request example
+15.2k Golang : Get timezone offset from date or timestamp