复制并更改压缩文件存档

huangapple go评论58阅读模式
英文:

Copy and change zip archive

问题

我有一个包含许多文件(其他压缩文件、文本文件、gz压缩文件)的zip归档文件。需要创建一个具有相同结构的新zip文件。新zip文件中的一些信息必须被更改。例如,需要将所有文件中的所有 'a' 字母更改为字母 'b'。需要在不创建临时文件或解压缩到临时文件夹的情况下完成此任务。我该如何做到这一点?

英文:

I have a zip archive with a lot of files(other zip files, text files, gz archives) inside it. Need to create a new zip file with the same structure. Some info in the new zip must be changed. For example, need to change all 'a' letters in all files to the letter 'b'. Need to resolve the task without creating temp files or unpacking archives to the temp folders. How can I do it?

答案1

得分: 1

如果您需要完全以流方式进行此操作,您将需要解析zip文件格式,将那些未被修改的条目复制到一个新的zip文件中,并处理那些正在被修改的条目,方法是将它们解压缩并以流方式重新压缩,然后复制到新的zip文件中。

如果您不需要以流方式进行操作,那么可以提取您想要修改的条目,将它们从zip文件中删除。进行修改。然后使用任何zip工具将它们添加到zip文件中。

英文:

If you need to do this entirely streaming, you will need to parse the zip file format, copy entries that are not being modified to a new zip file, and process entries that are being modified by decompressing them and recompressing them in streams, copying to the new zip file.

If you don't need to do this streaming, then extract the entries you want to modify, removing them from the zip file. Modify them. Then add them to the zip file using any zip utility.

huangapple
  • 本文由 发表于 2020年10月4日 16:03:52
  • 转载请务必保留本文链接:https://go.coder-hub.com/64192390.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定