jszip
jszip copied to clipboard
Get size
Hi,
How could I get the size of each files inside a zip after a.load
?
Sorry, I was sure I added a comment some days ago...
You can't with the current version. This information is stored in _data.compressedSize (like in zip.file("...")._data.compressedSize
) but this is not a public API and it can/will change without notice.
It sounds interesting, we should maybe add a way to extract cleanly these informations.
For now I compute the size based on the base64 data (base64.length * 0.75
). It's seems right but I find that a bit hacky.
Thanks for the answer and your work.
zip.file("...")._data.compressedSize
is no longer accessible with the latest version. Is there any other way to access the size of the file in browser memory?
One way is to use the forEach method JSZip#forEach(callback)
like:
let size = 0;
zip.forEach((file) => size += file ? 1 : 0);
I also needed this so I can set content-length:
res.writeHead(200, {
'Content-Type': 'application/zip',
'Content-Length': size // typically got with fs.stat
});
just convert it to blob
Converting it to blob is not efficient. just need to get the size from the metadata of that file. Please suggest better approach without affecting the performence