Skip to content

Instantly share code, notes, and snippets.

@PeterBooker
Created June 17, 2018 21:04
Show Gist options
  • Save PeterBooker/5da7079ef783c8c5c492f3e159065d1f to your computer and use it in GitHub Desktop.
Save PeterBooker/5da7079ef783c8c5c492f3e159065d1f to your computer and use it in GitHub Desktop.
Example of current Zip download and extraction code
package slurper
func GetExtensions(items []string) {
for _, item := range items {
data := downloadZip(item)
extractZip(data)
}
}
func downloadZip(name string) ([]byte) {
var content []byte
var err error
// do HTTP request
resp := httpRequest()
content, err = ioutil.ReadAll(resp.Body)
if err != nil {
panic(err)
}
return content
}
func extractZip(data []byte) {
length := int64(len(data))
zr, err := zip.NewReader(bytes.NewReader(content), length)
if err != nil {
panic(err)
}
// extract Zip Archive files
extractFiles()
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment