Lukas Lukas - 1 year ago 64
Node.js Question

Get md5 checksums of entries in zip using adm-zip

I am trying to get MD5 checksums for all files in a ZIP file. I am currently using

for this because I read I can read zip contents into the memory without having to extract a file to the disk. But I am failing to read the data of entries in a ZIP file. My code goes as follows:

var zip = new AdmZip(path);
.map(entry => { console.log(entry.entryName,; });

can be read, so opening and reading the zip works. But
is always
. I read that
is not really the method to read the data of an entry, but I am not sure how to actually read it.

Answer Source

To read the data of the entry, you must call the method getData() of the entry object, which returns a Buffer. Here is the updated code snippet which works on my end :

var zip = new AdmZip(path);
zip.getEntries().map(entry => {
  const md5Hash = crypto.createHash('md5').update(entry.getData()).digest('hex');

I used the basic crypto module to produce the md5 hash (in hex format). Don't forget to add it to the list of your requires at the top of your file: const crypto = require('crypto');