-
Notifications
You must be signed in to change notification settings - Fork 375
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Invalid or unsupported zip format. No END header found #268
Comments
Did you ever find a fix for this? |
@AzureZhen I've found macos is using an util called |
@jerrygreen , I am facing same issue. How do you fix it by using ditto? could you please attach sample code here? Many thanks. |
ditto -xk /path/from /path/to |
This error is thrown cases when file comment field exceeds maximum 65k size. I have seen it with some external signing schemes. |
Anyone still experiencing the issue? Would appreciate a solution that is not dependent 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 |
Are you able extract or view your file with archive managers like 7zip, WinRAR etc. ? |
@5saviahv Yes, the file seems to be okay and extracts with these tools I've tried:
I also seem to only get this error sometimes, not all the time (using the same file) which makes it slightly more challenging to understand the cause. Thanks! |
Interesting, there maybe many culprits, but in way you describe it, it seems like race condition (two or more process wants access the file at same time)
|
Thanks for getting back to me on this. A race condition could be the case, after the file is extracted the contents are copied and then the original zip file and extracted folder are removed. Do you use async functions? I am unsure but I have provided an example below. It fails on which OS? It fails when running the script on Node Here's the function I have: _extractZip(projectName, fileZipName, copyPath=null) {
const extractedFolder = `./${projectName}/${fileZipName.replace('.zip', '')}`;
// Extracts contents of zip file.
const extractPath = `./${projectName}/${fileZipName}`;
const zip = new AdmZip(extractPath);
zip.extractAllTo(`${projectName}/`, true);
let extractError = null;
// If a copy path is not provided files won't be moved.
if (copyPath) {
fse.copy(extractedFolder, copyPath, { overwrite: true }, err => {
if (err) {
extractError = `
Could not copy files to ./${copyPath}. \n
./${err}
`
} else {
// Cleans up by removing extracted folder and zip.
try {
fs.rmdirSync(extractedFolder, { recursive: true });
} catch (err) {
extractError = `
Could not remove extractedFolder. \n
./${err}
`
}
// Remove zip file as it is not longer needed.
try {
fs.unlinkSync(extractPath);
} catch (error) {
extractError = `
Could not remove ./${extractPath}. \n
./${err}
`
}
}
});
} else {
// Cleans up by removing extracted folder and zip.
// Lets user know that program did not work as intended.
try {
fs.rmdirSync(extractedFolder, { recursive: true });
} catch (err) {
extractError = `
Could not remove extractedFolder. \n
./${err}
`
}
// Remove zip file as it is not longer needed.
try {
fs.unlinkSync(extractPath);
} catch (error) {
extractError = `
Could not remove ./${extractPath}. \n
./${err}
`
}
this.log(`${chalk.red('Error:')} Could not copy files (copyPath is not present).
Zip file and extracted files were removed.`);
}
} Thanks again for looking into it. If this is a race condition is there a way to only access the file when it is done extracting? |
Code seems ok. It should not give any trouble. |
How big your files are ? I mean aren't any of them Zip64 ? Many archive managers switch Zip64 if you use big files or you have many files. Adm-zip can read zip64 files but it has higher chance for fail. |
@5saviahv thank you, for some reason I cannot replicate the error lately. I am not sure whether it is Since this is so intermittent (on that same file) I am unsure what might be cause it but I haven't been getting the error lately. |
This happened to me once, but when retrying (same code, same file) it works. Weird. |
I have this same issue. I download the file from my aws-s3 then use adm to unzip then use it with cheerio. The trick is I need to leave my computer alone for like 5-10 minutes and run my code and it will sometime (around 40% of the time) give the error "Invalid or unsupported zip format. No END header found". But otherwise it will work fine. Here is my code.
I can't let this happen in production though. The file must be processed and served to customer. |
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.
|
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. |
I had this problem, and turns out the URL was returning a http code 302 (redirect), instead of a 200 (success). then my zip file was getting 0 bytes. to fix that I changed the code a bit:
|
My issue here was that I passed |
I had the same problem downloading a file using I solved by waiting on the writeStream' import os from 'os'
import fs from 'fs';
import path from 'path';
import axios from 'axios';
import AdmZip from 'adm-zip';
async function download(url: string): Promise<string> {
const outputFile = path.join(os.tmpdir(), 'archive.zip');
const { data } = await axios.get(url, { responseType: 'stream' });
// Pipe the data to a file
const writeStream = fs.createWriteStream(outputFile);
data.pipe(writeStream);
// Return a promise and resolve when download finishes
return new Promise((resolve, reject) => {
data.on('error', () => {
reject(`Failure while retrieving remote data (source: ${downloadURL})`);
})
writeStream.on('close', () => {
resolve(outputFile);
})
writeStream.on('error', err => {
reject(err);
})
})
}
async function extract(url: string, outputDir: string) {
// 1. Download the zip file
const file = await download(url);
// 2. Extract the archive
const zip = new AdmZip(file);
zip.extractAllTo(outputDir, /*overwrite*/ true);
return outputDir;
}
extract("https://example.com/archive.zip", path.join(os.tmpdir(), 'extracted')).catch((error) => {
console.error(error);
}); |
In my case it was my fault with curl and the way I was passing my binary.
|
I found the problem for me:
Right ✅:
I think, we have to create a maybe it's why i get a |
Error:
My (simple) code:
I'm using
Macos 10.14.1
By opening it from Finder (using default Archive Utility app) it's unzipping nicely, no problems
The text was updated successfully, but these errors were encountered: