Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Compressing huge files (> 2GB) into ZIP on the client side

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.

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?

like image 999
Enrique Moreno Tent Avatar asked Nov 07 '12 13:11

Enrique Moreno Tent


People also ask

How do I zip a 2gb file?

To zip (compress) a file or folder Locate the file or folder that you want to zip. Press and hold (or right-click) the file or folder, select (or point to) Send to, and then select Compressed (zipped) folder. A new zipped folder with the same name is created in the same location.

Can a file be too big to zip?

For reference purposes, with the Zip64 extension to the Zip file format enhancement, Zip files of 16 exabytes, which is over 16 billion gigabytes (or 2 to the 64th power bytes) are possible. Likewise, over 4 billion files and folders can be included in a Zip file.

What if compressed ZIP file is still too big?

Split the file into multiple parts to share and the recipient can reconstitute the parts into a single file. A good example of this is the RAR format, of which there are a number of great (free) solutions such as 7-Zip. Try other zip compression algorithms such as 'Zipx' or '.


1 Answers

You can compress up to 4GB of data with zip.js but:

  • it will work only with Chrome
  • it will be quite slow (approx. 30min per GB of compressed data on my old laptop)

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).

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.

Edit: 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

Here is an example of custom Writer and Reader constructors. You can also look at zip.js Writers implementations for more examples.

like image 169
check_ca Avatar answered Sep 28 '22 06:09

check_ca