Android 修改 Zip 文件
有没有什么方法可以在 Android 上修改 zip 而无需提取其内容?我只需要添加/删除大约 10 个文件。如果我必须解压该 zip 文件,它可能会达到 200mb。
Is there any way of modifying a zip on android without having to extract its contents? I only need to add/remove about 10 files. If I had to extract the zip it could go up to 200mb.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
没有第三方软件包似乎是不可能的。 使用 Java 将文件附加到 zip 文件
我仍然会等待答案...
Seems its not possible without 3rd party packages. Appending files to a zip file with Java
I'll still wait for answers...
我认为您不会找到一种简单的方法来使用内置库来做到这一点。如果这是您应用程序的核心功能,您可能需要编写自己的功能(解析 zip 并不难)。
一般方法如下:开始读取 zip,识别第一个 zip 条目标头 - 当您找到要排除的条目的标头时,只需继续读取下一个条目 - 否则,写出。跟踪每个 zipentry 的输出偏移量。然后在文件末尾写入您自己的 zip 预告片。
zip 格式定义良好(并且不是特别复杂 - 特别是 b/c,您不必使用 flate 或 deflate 或加密或类似的东西),并且您想要做的事情很简单: http://www.pkware.com/documents/casestudies/APPNOTE.TXT
另一方面,如果这不是您的应用程序的核心功能,请找到并许可一个可以做到这一点的库(我怀疑您是否会找到这样做的开源实现)并继续。
I don't think you are going to find an easy way to do this with built in libraries. If this is a core function of your application, you may want to write your own (parsing zip isn't that hard).
Here's the general approach: start reading the zip, identify the first zip entry header - when you find the header for the entry you want to exclude, just keep reading to the next entry - otherwise, write out. Keep track of the output offset of each zipentry. Then write your own zip trailer at the end of the file.
The zip format is well defined (and not particularly complex - especially b/c you won't have to muck with flate or deflate or encryption or anything like that), and what you are trying to do is straightforward: http://www.pkware.com/documents/casestudies/APPNOTE.TXT
On the other hand, if this is not a core piece of functionality for your app, find and license a library that can do it (I doubt that you'll find open source implementations that do) and move on.