adm-zip: Invalid or unsupported zip format. No END header found

Error:

Jerrys-MacBook-Pro:client jerrygreen$ node zip.js 

/Users/jerrygreen/my_project/node_modules/adm-zip/zipFile.js:66
			throw Utils.Errors.INVALID_FORMAT;
			^
Invalid or unsupported zip format. No END header found

My (simple) code:

const AdmZip = require('adm-zip')
const zip = new AdmZip('./my_file.zip')

I’m using Macos 10.14.1 By opening it from Finder (using default Archive Utility app) it’s unzipping nicely, no problems

About this issue

  • Original URL
  • State: open
  • Created 6 years ago
  • Reactions: 24
  • Comments: 20

Most upvoted comments

I made a workaround for this as I was getting the zip file externally and then saved locally to extract.

A setTimeout solved my issue.

	const saveZIPFile = async () => {
		return new Promise((resolve) => {
			data.body.pipe(fs.createWriteStream(path.resolve(__dirname, `${project}.zip`)));

			data.body.on('end', () => {
				setTimeout(() => {
					resolve();
				}, 1000);
			});
		});
	};

	await saveZIPFile();

	var zip = new AdmZip(path.resolve(__dirname, `${project}.zip`));

	zip.extractAllTo(path), true);

Anyone still experiencing the issue? Would appreciate a solution that is not dependent on ditto if possible.

const zipPath = `./temp/file.zip`;
const zip = new AdmZip(zipPath);
zip.extractAllTo(`./temp/`, true);

The terminal output is:

Error: Invalid or unsupported zip format. No END header found
    at readMainHeader (/Users/username/Projects/example-project/node_modules/adm-zip/zipFile.js:107:10)
    at new module.exports (/Users/username/Projects/example-project/node_modules/adm-zip/zipFile.js:19:3)
    at new module.exports (/Users/username/Projects/example-project/node_modules/adm-zip/adm-zip.js:20:11)
    at module.exports._installWordpress (/Users/username/Projects/example-project/generators/app/index.js:102:17)
    at module.exports.writing (/Users/username/Projects/example-project/generators/app/index.js:45:12)
    at Object.<anonymous> (/Users/username/Projects/example-project/node_modules/yeoman-generator/lib/index.js:399:25)
    at /Users/username/Projects/example-project/node_modules/run-async/index.js:49:25
    at new Promise (<anonymous>)
    at /Users/username/Projects/example-project/node_modules/run-async/index.js:26:19
    at /Users/username/Projects/example-project/node_modules/yeoman-generator/lib/index.js:400:11

I had the same problem and it turned out to be an issue with how I download the file. I never waited for the download to complete before attempting to unzip it.

Solution: Properly await the download and only then start working with the ZIP file.

This happened to me once, but when retrying (same code, same file) it works. Weird.