How to use the tar.gz function in tar

To help you get started, we’ve selected a few tar examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github ioBroker / ioBroker.js-controller / lib / backup.js View on Github external
name = name.replace(/\\/g, '/');
        if (name.indexOf('/') == -1) {
            name = getBackupDir() + name;
            var regEx = new RegExp('_backup' + tools.appName, 'i');
            if (!regEx.test(name)) name += '_backup' + tools.appName;
            if (!name.match(/\.tar\.gz$/i)) name += '.tar.gz';
        }
        if (!fs.existsSync(name)) {
            console.log('Cannot find ' + name);
            processExit(11);
        }
        var TARgz = require('tar.gz');
        if (fs.existsSync(__dirname + '/../tmp/backup/backup.json')) fs.unlinkSync(__dirname + '/../tmp/backup/backup.json');

        new TARgz().extract(name, __dirname + '/../tmp', function (err) {
            if (err) {
                console.log('Cannot extract from file "' + name + '"');
                processExit(9);
            }
            if (!fs.existsSync(__dirname + '/../tmp/backup/backup.json')) {
                console.log('Cannot find extracted file from file /../tmp/backup/backup.json"');
                processExit(9);
            }
            // Stop controller
            var daemon = require('daemonize2').setup({
                main:       '../controller.js',
                name:       tools.appName + ' controller',
                pidfile:    __dirname + '/' + tools.appName + '.pid',
                cwd:        '../',
                stopTimeout: 1000
            });
github arterli / CmsWing / src / admin / controller / database.js View on Github external
targzAction() {
        // Streams
        if (this.isGet()) {
            let paths = think.RESOURCE_PATH;
            let path = "/backup/";
            let dir = paths + path + this.get("dir");
            let tar = paths + path + this.get("dir") + ".tar.gz"
            if (!think.isFile(tar)) {
                //var read = targz().createReadStream(dir);
                //var parse = fs.createWriteStream(tar);
                //read.pipe(parse);
                let self = this;
                targz().compress(dir, tar)
                    .then(function () {
                        self.success({'name': "tar", 'url': self.get("dir")})
                    })
                    .catch(function (err) {
                        console.log('Something is wrong ', err.stack);
                    });

            } else {
                this.success({'name': "download", 'url': this.get("dir")})
            }
        } else if (this.isPost()) {
            let paths = think.RESOURCE_PATH;
            let path = "/backup/";
            let tar = paths + path + this.post("name") + ".tar.gz"
            this.download(tar);
        }
github mikefrey / node-pac / lib / bower / strategy.js View on Github external
}), function (file, cb) {
    var archive = Path.join(self.modulePath, file);
    file = file.replace(/\.tgz$/i, '');
    var name = file.substring(0, file.lastIndexOf(sep));
    var version = file.substring(file.lastIndexOf(sep) + sep.length);

    if (deps[name]) {
      // remove existing installed module
      rimraf.sync(Path.join(destPath, name));

      // extract the module into node_modules
      new tgz().extract(archive, destPath, function (err) {
        if (!err) {
          log('Extracted', name + '@' + version);
        } else {
          error(err);
        }
        cb();
      });
    } else {
      cb();
    }
  }, function () {
    log('\nDone!');
github arei / npmbox / npmboxxer.js View on Github external
// Contents have not changed in size since the previous
						// iteration. Done!
						callback();
					} else {
						// Contents have changed. Note the new size, delay a
						// moment, and then check again.
						prevSize = totalSize;
						setTimeout(checkIfDone,250);
					}
				})
				.on("error",function(err){
					return callback(err);
				});
		};

		new targz().extract(source,target,checkIfDone);
	};
github mikefrey / node-pac / installer.js View on Github external
async.eachSeries(glob.sync('*.tgz', {cwd:modulePath}), function(file, cb) {
    var archive = Path.join(modulePath, file)
    file = file.replace(/\.tgz$/i, '')
    var name = file.substring(0, file.lastIndexOf(sep))
    var version = file.substring(file.lastIndexOf(sep)+sep.length)

    // remove existing installed module
    if (fs.existsSync(Path.join(nodeModulesPath, name))) {
      fs.rmdirSync(Path.join(nodeModulesPath, name))
    }

    // extract the module into node_modules
    new tgz().extract(archive, nodeModulesPath, function(err) {
      if (!err) log('Extracted', name+'@'+version)
      else error(err)
      cb()
    })

  }, function() {
    log('Done! Now run \'npm rebuild\'')
github Softmotions / ejdb-node / platform.js View on Github external
function processArchive() {
                var targz = require("tar.gz");
                console.log("Unzip archive '%s'", zfile);
                var tgz = new targz();
                tgz.extract(zfile, sdir, function(err){
                    if (err) {
                        console.log(err);
                        process.exit(1);
                        return;
                    }

                    sdir = path.resolve(sdir);

                    var config = {};
                    config["variables"] = {
                        "EJDB_HOME" : sdir
                    };
                    fs.writeFileSync("configure.gypi", JSON.stringify(config));

                    var args = ["configure", "rebuild"];
github Dineshs91 / devlog / tasks / e2e-setup.js View on Github external
var extractChromedriver = function(cbdone) {
            grunt.log.writeln('Extracting node-webkit chromedriver.');

            if (config.platform === 'linux') {
                var targz = require('tar.gz');
                var compress = new targz().extract(chromeDriverLocal, support_dir, function(err) {
                    if(err)
                        console.log(err);

                    var cdSrc = path.resolve(chromeDriverLocal.replace(/\.tar\.gz$/, ''), 'chromedriver');
                    fs.renameSync(cdSrc, chromeDriverFile);
                    grunt.log.writeln('e2e setup is complete.');
                    cbdone();
                });
            } else {
                fs.createReadStream(chromeDriverLocal)
                    .pipe(unzip.Parse())
                    .on('entry', function (entry) {
                        if (entry.path.indexOf('/chromedriver') >= 0) {
                            entry.pipe(fs.createWriteStream(chromeDriverFile));
                        } else {
                            entry.autodrain();
github sciencefair-land / sciencefair / bin / package.js View on Github external
packager(Object.assign({}, all, linux), function (err, buildPath) {
    if (err) return cb(err);
    console.log('Linux: Packaged electron. ' + buildPath);
    var targetPath = path.join(DIST_PATH, BUILD_NAME + '_linux-x64.tar.gz');
    rimraf.sync(targetPath);
    targz().compress(buildPath[0], targetPath).then(function() {
      console.log('Linux: Created tarball ' + targetPath);
      }).catch(cb);
  })
}
github knalli / angular-vertxbus / build_tools / upload-github-release.js View on Github external
const buildTarGzArchive = ({lookupDir, archiveFilePath}) => {
  let gzipOptions = {
    level : 9,
    memLevel : 9,
  };
  let tarOptions = {
    fromBase : true
  };
  return new TarGz(gzipOptions, tarOptions)
    .compress(lookupDir, archiveFilePath)
    .then(() => archiveFilePath);
};
github evolus / pencil / app / pencil-core / common / EpgzHandler.js View on Github external
return new Promise(function (resolve, reject) {
        var path = null;
        var targz = require('tar.gz');
        new targz({}, {fromBase: true}).compress(Pencil.documentHandler.tempDir.name, documentPath)
        .then(resolve).catch(reject);
    });
};