Skip to content

Instantly share code, notes, and snippets.

@avelino
Last active April 6, 2023 11:13
Show Gist options
  • Save avelino/8776f3d45f7d59ef4930 to your computer and use it in GitHub Desktop.
Save avelino/8776f3d45f7d59ef4930 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