jszip icon indicating copy to clipboard operation
jszip copied to clipboard

Get size

Open ghigt opened this issue 9 years ago • 7 comments

Hi,

How could I get the size of each files inside a zip after a.load?

ghigt avatar Dec 17 '15 17:12 ghigt

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.

dduponchel avatar Dec 28 '15 21:12 dduponchel

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.

ghigt avatar Dec 29 '15 12:12 ghigt

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?

mhirsch avatar Oct 24 '18 19:10 mhirsch

One way is to use the forEach method JSZip#forEach(callback)

like:

let size = 0;
zip.forEach((file) => size += file ? 1 : 0);

pheliperocha avatar Mar 08 '19 18:03 pheliperocha

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
});

Noitidart avatar Sep 28 '22 18:09 Noitidart

just convert it to blob

sirarifarid avatar Oct 24 '22 15:10 sirarifarid

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

salauddinn avatar Sep 21 '23 11:09 salauddinn