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

364
Visualizações
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 Respostas
Responde à pergunta

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 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