Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

311
Visualizações
How to catch createReadStream error in node js?

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!

about 4 years ago · Juan Pablo Isaza
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda