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

363
Vistas
How could I check If a zip file is corrupted in NodeJS?

I would check if a ZIP file is corrupted using NodeJS using less CPU and memory as possible.

How to corrupt a ZIP file:

  1. Download a ZIP file
  2. Open the ZIP file using a text editor optimized like Notepad++
  3. Rewrite the header. Only put random characters.

I am trying to reach this goal using the NPM library "node-stream-zip"

  private async assertZipFileIntegrity(path: string) {
    try {
      const zip = new StreamZip.async({ file: path });
      const stm = await zip.stream(path);
      stm.pipe(process.stdout);
      stm.on('end', () => zip.close());
    } catch (error) {
      throw new Error();
    }
  }

However, when I run the unit tests I receive an error inside an array:

Rejected to value: [Error]

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0


import zip from 'yauzl';
import path from 'path';

const invalidZipPath = path.resolve('invalid.zip');
const validZipPath = path.resolve('valid.zip');

const isValidZipFile = (filePath) => {


    return zip.open(filePath, { lazyEntries: true }, (err, stream ) => {

        if (err) {
            
            console.log('fail to read ', filePath);
            return false;

        }
            
        console.log('success read ', filePath);
        return true;

    });

}

isValidZipFile(validZipPath);
isValidZipFile(invalidZipPath);


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