file data stream has unexpected number of bytes

559 Views Asked by At

i used this package to create this function https://github.com/archiverjs/node-archiver

import archiver from "archiver";
import fs from "fs";

async function compressDirToZip(inputDirPath:string, outputFilePath:string) {

return new Promise<void>((resolve, reject) => {
    const output = fs.createWriteStream(outputFilePath);
    const archive = archiver('zip',{zlib:{level: 9}});

    output.on('close', () => {
      resolve();
    });

    archive.on('warning', warning => {
      console.warn(warning);
    });

    archive.on('error', error => {
      reject(error);
    });

    archive.pipe(output);

    const stat = fs.statSync(options.inputDirPath);

    if (stat.isDirectory()) {
      archive.directory(inputDirPath, false);
    } else {
      reject(`${inputDirPath} is not a directory`);
    }

    archive.finalize();
  });
}

When i try to use it to compress a directory, i get the error :

Error: file data stream has unexpected number of bytes
    at ByteCounter.<anonymous> (project/node_modules/yazl/index.js:160:99)
    at ByteCounter.emit (node:events:525:35)
    at endReadableNT (node:internal/streams/readable:1359:12)
    at process.processTicksAndRejections (node:internal/process/task_queues:82:21)
Emitted 'error' event on ZipFile instance at:
    at ByteCounter.<anonymous> (/project/node_modules/yazl/index.js:160:85)
    at ByteCounter.emit (node:events:525:35)
    at endReadableNT (node:internal/streams/readable:1359:12)
    at process.processTicksAndRejections (node:internal/process/task_queues:82:21)

If i try running the app in debug mode, everything works smothly.

0

There are 0 best solutions below