I tried to download zip files using node-fetch.
File successfully download and I can read the json file inside the zip using adm-zip NPM package.
But some times getting error when reeding the downloaded file. The zip file is corrupted during download.
When unzipping from file, it goes to .cpgz
format
async function download(url, location) {
try {
const res = await fetch(url);
await new Promise(async (resolve, reject) => {
const fileStream = fs.createWriteStream(location);
res.body.pipe(fileStream);
res.body.on("error", (err) => {
reject(err);
});
fileStream.on("finish", function () {
resolve();
});
});
return
} catch (e) {
console.log("Err on download files ", e)
}
}
Reading this file using const zip = new AdmZip(file);
throwing error UnhandledPromiseRejectionWarning: Error: Invalid or unsupported zip format. No END header found
I just make console for in the first section of code
const res = await fetch(url);
console.log(res)
Successfull files return PassThrough { _readableState: ReadableState { ..... ..... writable: true,
But for failed files
Gunzip {
_writeState: Uint32Array [ 0, 0 ],
_readableState: ReadableState {
....
....
writable: false,
Anyone can help?