从 zip 存档中提取 zip 文件,而不将整个文件加载到内存中
有没有办法从 Adobe AIR 中的 zip 文件中提取单个文件?
我正在使用 NoChumps zip 库从 zip 中提取文件。在这个库中,整个 IDataStream 被加载到内存中,之后您可以轻松提取文件条目。如果 zip 大小为 5 到 10MB,则没有问题。但是当 zip 大小为 80MB 时(很多都是这样),80MB 会被加载到内存中。这会导致应用程序崩溃并且在移动设备上运行缓慢。根据 zip 规范,
“ZIP 文件由位于文件末尾的中央目录来标识,这允许附加新文件。该目录存储条目(文件或目录)名称的列表与有关该条目的其他元数据以及 ZIP 文件中的偏移量一起存储在 ZIP 文件中,该偏移量指向实际的条目数据。”
另外,我无法控制 zip 文件的大小,但大多数平均大小为 60 到 100MB。里面的文件大约有4MB。
Is there a way to extract a single file from a zip file in Adobe AIR?
I'm using NoChumps zip library to extract files from a zip. In this library the entire IDataStream is loaded into memory and after that you can extract file entries easily. In cases where the zip is 5 to 10MB there are no problems. But when the zip is 80MB, which many are, 80MB is loaded into memory. This causes the app to crash and run slow on mobile devices. According to the zip specification,
"A ZIP file is identified by the presence of a central directory located at the end of the file, this allows appending of new files. The directory stores a list of the names of the entries (files or directories) stored in the ZIP file, along with other metadata about the entry, and an offset into the ZIP file, pointing to the actual entry data."
Also, I do not have control of the size of zip files but most average is 60 to 100MB. Files inside are ~4MB.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这对于 Flex 来说是不可能的,但对于 AIR 来说是可能的。 AIR 具有具有随机访问功能的 File 类,它允许读取 zip 文件列表。我使用了 Coltware 的 airxzip,效果很好。创建
ZipFileReader
,打开您的zip文件,调用getEntries()
,找到您需要的条目并调用reader.unzip(entry)
。It's not possible for Flex, but possible for AIR. AIR got File class with random access, which allows to read zip file list. I used Coltware's airxzip and it served me well. Create
ZipFileReader
, open your zip file, callgetEntries()
, locate entry you need and callreader.unzip(entry)
.快速回答 - 不,这是不可能的。
长答案 - 您需要制作一个使用 zLib 这样的库的辅助程序,并将其安装在计算机上
The quick answer - no it is not possible.
The long answer - you need to make a secondary program that use a library like zLib and have that installed on the machine also