-
-
Save lujiacn/8fa0c20c35ccc879256912744b4ae39a to your computer and use it in GitHub Desktop.
golang gzip stream
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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