dongleibeng5602
2013-12-04 00:27
浏览 132
已采纳

从网上获取zip文件并在Go中解压缩

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?

图片转代码服务由CSDN问答提供 功能建议

如何从Web上获取zip存档文件并在Go中解压缩? 看起来 archive / zip 包提供了一组分析压缩文件的工具。 但是,为了解压缩压缩文件,我必须使用 zip.OpenReader ,它将文件名作为字符串。

所以我如何获取压缩文件 Web中的文件,并将其作为字符串放入上述函数中...? 或者,也许我必须首先获取文件并将其放入文件系统的一个目录中,然后再读取它?

  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

1条回答 默认 最新

  • duanjianqu3685 2013-12-04 03:29
    已采纳

    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))
    
    已采纳该答案
    打赏 评论

相关推荐 更多相似问题