How can I fetch a zip archived file from the Web and decompress it in Go? It looks like archive/zip
package provides a set of tools to parse the zipped file. However, in order to decompress the zipped file, I have to use zip.OpenReader
, which takes the filename as string.
So how can I fetch the zipped file from the Web, and put it into the above function as string...? Or maybe do I have to first fetch the file and put it in one of the directories of my filesystem, and then read it?
It appears that in order to decompress a zip, you need to be able to seek to arbitrary locations. This means that unless you want to do something fancy, it either needs to be a local file or be completely in memory.
Assuming you have downloaded the zip and have it in a []byte
, you want to do something like:
zipReader := zip.NewReader(bytes.NewReader(zipData), len(zipData))
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.