Fetch zip file from the web and decompress it in Go

go, zip

Solution

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))

Problem

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?

Original source