Is there anyway to override the date (Checksum of zip mismatched) ?
See original GitHub issueI’m writing a file to zip on upload:
/**
* @method compressAndHash
* @description Returns an object that has the compressed file in a buffer, and the representing md5 checksum
* @param buffer
* @param fileName The name of the output file in the zip
*/
private compressAndHash(buffer: Buffer, fileName: string) {
const zip = new admZip();
zip.addFile(fileName, buffer);
const bufferedZip = zip.toBuffer();
return {
compressedFile: bufferedZip,
hash: this.createHash(bufferedZip)
};
}
/**
* @method createHash
* @description Generates md5 for a given buffer
* @param buffer
*/
private createHash(buffer: Buffer) {
const hash = crypt
.createHash('md5')
.update(buffer)
.digest('base64');
return hash;
}
}
But it looks like the “date” is part of the checksum. Is there anyway to override the date? Similar to the issue/solution mentioned in https://github.com/archiverjs/node-archiver/issues/82 so we can get consistent checksums?
Issue Analytics
- State:
- Created 5 years ago
- Reactions:1
- Comments:8
Top Results From Across the Web
Zip File md5 Checksum - Every Time Different
Reason is that zip file contains at least timestamp information about files. And this is what change you md5sum. Every zip entry is...
Read more >Why doesn't changing a file's name change its checksum?
Changing the file's name (or ownership or timestamps or permission etc.) or accessing it via one of its other names or symbolic links,...
Read more >Checksum with no creation date - Google Groups
Hi I want to implement a jar comparation files application using a checksum. Two jar files should be the same if both have...
Read more >Md5 checksum different after gunzip and gzip - Super User
The standard Unix file utility gives you some basic info about a .gz file, e.g.: $ file foo.gz foo.gz: gzip compressed data, was...
Read more >Different md5sums for same tar contents - Server Fault
Show the tar commandline that you are using. There shouldn't be any difference unless the files are being modified. Even touch filename which ......
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Hi @ClaytonAstrom,
I recently ran into this exact issue. I ended up mocking the date use in
date.Now()
which is used insideamd-zip
. We now get a consistent now get a checksum.Apparently dates are apart of the zip spec, and
adm-zip
isn’t doing anything out of the ordinary here.Hopefully this is useful! Thanks, Ollie
adm-zip wraps internal structures so you cant see them directly. one idea is after you call:
zip.addfile(filename, ...);
you also call
zip.getEntry(filename).header.time = new Date("some known date");
and after that you call toBuffer()