lib/utils/compression.js
function(sourceDir, destFile, opts) {
        opts = opts || { archive_path: '/' };
        return new Promise(function(resolve, reject) {
            // pack
            var tempFile = destFile + '.tmp.tar';
            try {
                var archive = archiver.create('tar');
                var output = fs.createWriteStream(tempFile);
                output.on('finish', function () {
                    resolve(tempFile);
                });
                archive.pipe(output);
                archive.directory(sourceDir, opts.archive_path);
                archive.finalize();
            } catch (err) {
                reject(err);
            }
        })
        .then(function(tempFile) {
            // compress
            try {
                var data = new Buffer(fs.readFileSync(tempFile), 'utf8');
                var compressed = new Buffer(Bzip2.compressFile(data));
                fs.writeFileSync(destFile, compressed);
                return destFile;
            } catch(err) {
                throw err;
            } finally {
                rimraf.sync(tempFile);
            }
        });
    }
function(sourceDir, destFile, opts) {
        opts = opts || { archive_path: '/' };
        return new Promise(function(resolve, reject) {
            // pack
            var tempFile = destFile + '.tmp.tar';
            try {
                var archive = archiver.create('tar');
                var output = fs.createWriteStream(tempFile);
                output.on('finish', function () {
                    resolve(tempFile);
                });
                archive.pipe(output);
                archive.directory(sourceDir, opts.archive_path);
                archive.finalize();
            } catch (err) {
                reject(err);
            }
        })
        .then(function(tempFile) {
            // compress
            try {
                var data = new Buffer(fs.readFileSync(tempFile), 'utf8');
                var compressed = new Buffer(Bzip2.compressFile(data));
                fs.writeFileSync(destFile, compressed);
                return destFile;
            } catch(err) {
                throw err;
            } finally {
                rimraf.sync(tempFile);
            }
        });
    }
function ( sourceDir , destFile , opts ) { opts = opts || { archive_path : '/' } ; return new Promise ( function ( resolve , reject ) { // pack var tempFile = destFile + '.tmp.tar' ; try { var archive = archiver . create ( 'tar' ) ; var output = fs . createWriteStream ( tempFile ) ; output . on ( 'finish' , function ( ) { resolve ( tempFile ) ; } ) ; archive . pipe ( output ) ; archive . directory ( sourceDir , opts . archive_path ) ; archive . finalize ( ) ; } catch ( err ) { reject ( err ) ; } } ) . then ( function ( tempFile ) { // compress try { var data = new Buffer ( fs . readFileSync ( tempFile ) , 'utf8' ) ; var compressed = new Buffer ( Bzip2 . compressFile ( data ) ) ; fs . writeFileSync ( destFile , compressed ) ; return destFile ; } catch ( err ) { throw err ; } finally { rimraf . sync ( tempFile ) ; } } ) ; }
Create a Bzip2 compressed tar of a directory.

@param sourceDir {string} the directory to be compressed
@param destFile {string} the output file
@param opts {{}}
@returns {Promise.<string>} path to the archive
Create a Bzip2 compressed tar of a directory .