Skip to content

Instantly share code, notes, and snippets.

@d4z3x
Forked from avelino/GzipStream.go
Created November 27, 2019 08:50
Show Gist options
  • Save d4z3x/26847d16170855727a222207ad1cc8c6 to your computer and use it in GitHub Desktop.
Save d4z3x/26847d16170855727a222207ad1cc8c6 to your computer and use it in GitHub Desktop.
golang gzip stream
func GetGzip(path string) string {
println(path)
client := &http.Client{
Transport: &transport.Transport{
ReadTimeout: 10 * time.Second,
RequestTimeout: 15 * time.Second,
},
}
resp, err := client.Get(path)
if err != nil {
panic(err)
}
defer resp.Body.Close()
gzipReader, err := gzip.NewReader(resp.Body)
if err != nil {
panic("couldn't create gzip reader")
}
csvReader := csv.NewReader(gzipReader)
for {
record, err := csvReader.Read()
println(record)
if err == io.EOF {
break
} else if err != nil {
panic("Error reading csv record: " + err.Error())
}
// TODO do whatever you need with the record
println(record)
}
return "test"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment