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

458
Visualizações
ERR Error: End of data reached (data length = 0, asked index = 4). Corrupted zip?

im making a whatsapp bot, im saving the chats in a excel file (im using exceljs) to read and handle some responses, i prefer to use promises and resolve them, i have a function to read chats:

const readChat = (number, message, step = null) =>
  new Promise((resolve, reject) => {
    setTimeout(() => {
      number = number.replace("@c.us", "");
      number = `${number}@c.us`;
      const pathExcel = `./chats/${number}.xlsx`;
      const workbook = new ExcelJS.Workbook();
      const today = moment().format("DD-MM-YYYY hh:mm");

      if (fs.existsSync(pathExcel)) {
        const workbook = new ExcelJS.Workbook();
        workbook.xlsx
          .readFile(pathExcel)
          .then(() => {
            const worksheet = workbook.getWorksheet(1);
            const lastRow = worksheet.lastRow;
            let getRowInsert = worksheet.getRow(++lastRow.number);
            getRowInsert.getCell("A").value = today;
            getRowInsert.getCell("B").value = message;

            if (step) {
              getRowInsert.getCell("C").value = step;
            }

            getRowInsert.commit();
            workbook.xlsx
              .writeFile(pathExcel)
              .then(() => {
                const getRowPrevStep = worksheet.getRow(lastRow.number);
                const lastStep = getRowPrevStep.getCell("C").value;
                resolve(lastStep);
              })
              .catch((err) => {
                console.log("ERR", err);
                reject("error");
              });
          })
          .catch((err) => {
            console.log("ERR", err);
            reject("error");
          });
      } else {
        const worksheet = workbook.addWorksheet("Chats");
        worksheet.columns = [
          { header: "Fecha", key: "number_customer" },
          { header: "Mensajes", key: "message" },
          { header: "Paso", key: "step" },
        ];

        step = step || "";

        worksheet.addRow([today, message, step]);
        workbook.xlsx
          .writeFile(pathExcel)
          .then(() => {
            resolve("STEP_1");
          })
          .catch((err) => {
            console.log("Error", err);
            reject("error");
          });
      }
    }, 1000);
  });

but the code after that else, its giving me the error: ERR Error: End of data reached (data length = 0, asked index = 4). Corrupted zip ?, the else, is supposed to be executed when there is no excel saved with that chat. I searched in many questions and pages, but i have not found any solution

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

I believe you would get this error after you stop your execution in between, i.e when the file is getting updated and this would corrupt the excel file.

You could try adding a "try catch" around read file in your if condition and create a new copy of workbook whenever you get these particular errors ('End of data reached (data length = 0, asked index = 4). Corrupted zip ?' or 'File not found:')

about 4 years ago · Juan Pablo Isaza Relatório
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