Skip to content

Instantly share code, notes, and snippets.

@prabhuvikas
Created May 15, 2020 14:18
Show Gist options
  • Save prabhuvikas/38dae6cc44dc782cd5f6451f67cbc329 to your computer and use it in GitHub Desktop.
Save prabhuvikas/38dae6cc44dc782cd5f6451f67cbc329 to your computer and use it in GitHub Desktop.

Revisions

  1. prabhuvikas created this gist May 15, 2020.
    22 changes: 22 additions & 0 deletions archiver-node.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,22 @@
    const archiver = require('archiver');

    /**
    * @param {String} source
    * @param {String} out
    * @returns {Promise}
    */
    function zipDirectory(source, out) {
    const archive = archiver('zip', { zlib: { level: 9 }});
    const stream = fs.createWriteStream(out);

    return new Promise((resolve, reject) => {
    archive
    .directory(source, false)
    .on('error', err => reject(err))
    .pipe(stream)
    ;

    stream.on('close', () => resolve());
    archive.finalize();
    });
    }