It's been 3 days struggling to catch an error in fs.createReadStream. There is a file when I try to unzip it it stuck while extracting and doesn't throw any error. Below is my code for reference:
const unzip = require("unzip-stream"),
function extractFileAndParse(file) {
return new Promise(function (resolve, reject) {
let extractedDirName = file.replace(".zip", "");
let unzipPipe = unzip.Extract({
path: `./directory/${extractedDirName}`,
});
try {
let stream = fs.createReadStream(`${directory}/${file}`).pipe(unzipPipe);
stream.on("finish", function () {
return resolve({
contentid: extractedDirName,
});
});
stream.on("error", (err) => {
return reject();
});
} catch (error) {
console.log("Error occurred while parsing the file: ", error);
reject();
}
});
}
For a normal file, once the extraction is done it goes to finish event and return the resolve(). But couldn't catch an error if it get stuck (or I don't know it doesn't throw an error) while extracting.
Any idea why? Thanks!