Verificaría si un archivo ZIP está dañado usando NodeJS usando menos CPU y memoria como sea posible.
Cómo corromper un archivo ZIP:
Estoy tratando de alcanzar este objetivo usando la biblioteca NPM "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(); } }Sin embargo, cuando ejecuto las pruebas unitarias, recibo un error dentro de una matriz:
Rechazado al valor: [Error]
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);