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?
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.
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.
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 '.
You can compress up to 4GB of data with zip.js but:
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With