将巨大的文件(> 2GB)压缩到客户端的ZIP中 [英] Compressing huge files (> 2GB) into ZIP on the client side
问题描述
我使用 node.js
和 socket.io
构建上传工具,因为它们通常会上传非常庞大的文件和普通的上传表格不起作用。问题是他们想在发送之前将文件压缩成拉链,以提高传输效率。
Im building an upload tool using node.js
and socket.io
, because they usually upload incredibly huge files and normal upload forms wouldnt work. The problem is that they wanted to compress the files into a zip before sending them, to increase efficiency in transmission.
我一直在研究像 JSZip 或 zip.js ,但这些都不适用于非常大的文件。我该怎么办?
I've been researching around compression methods like JSZip or zip.js, but neither of those work well with extremely big files. What could I do?
推荐答案
您可以使用 zip.js 但是:
- 它会仅适用于Chrome
- 它会很慢(我的旧笔记本电脑上每GB压缩数据约30分钟)
您可以通过此演示在线试用
You can try it online with this demo. You must select the "HDD" option in the "choose temporary storage" input. Then you can import big files from your filesystem and monitor the memory consumption: it should be stable (approx. 300MB on my laptop).
选择硬盘意味着拉链.js将使用文件API:目录和系统来存储压缩数据。此API目前仅适用于Chrome,并允许将数据写入沙盒虚拟文件系统。该演示使用不需要用户权限的临时存储。
Selecting "HDD" means that zip.js will use File API: Directories and System to store compressed data. This API is currently only available on Chrome and allows to write data into a sandboxed virtual filesystem. The demo uses the temporary storage which does not require a user permission.
编辑:您还可以实现自己的 Writer构造函数函数将数据流式传输到服务器,而zip.js压缩它:它不会依赖它在文件系统API上,应该适用于您支持的每个浏览器。 Writer必须实现这两种方法:
You could also implement your own Writer constructor function to stream the data to your server while zip.js compresses it: it wouldn't rely on the filesystem API and should work on every browser you support. A Writer must just implement these 2 methods:
init(callback[, onerror])
// initializes the stream where to write the zipped data
writeUint8Array(array, callback[, onerror])
// writes asynchronously a Uint8Array into the stream.
// getData method is optional
这是自定义Writer和Reader构造函数的示例。您还可以查看 zip.js作家更多示例的实现。
这篇关于将巨大的文件(> 2GB)压缩到客户端的ZIP中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!