Created
June 17, 2018 21:04
-
-
Save PeterBooker/5da7079ef783c8c5c492f3e159065d1f to your computer and use it in GitHub Desktop.
Example of current Zip download and extraction code
This file contains 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
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