Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

451
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda