function _extract( _zipfile , _cb ) { var unzipper = new DecompressZip( _zipfile ) unzipper.on('error', function ( _err ) { _cb( _err ); }); unzipper.on('extract', ( _log ) => { // get dirs list var dirs = []; var addon_dir = null; _log.forEach( ( _entry ) => { var obj_type = Object.keys( _entry )[0]; addon_dir = _entry[obj_type].split( path.sep )[0]; if ( dirs.indexOf( addon_dir ) === -1 ) { dirs.push( addon_dir ); } } ); _cb( null , dirs ); }); unzipper.on('progress', function (fileIndex, fileCount) { // maybe do some progress }); unzipper.extract({ path: addons_path }); }
Examples.prototype.unzipExamples = function unzipExamples() { var defer = when.defer(); var _this = this; if (fs.existsSync('tmp/node-webkit-examples.zip')) { this.yeoman.log.info('Unzip examples.'); var unzipper = new DecompressZip('tmp/node-webkit-examples.zip'); unzipper.on('error', function (error) { _this.yeoman.log.conflict('Error while unzipping "tmp/node-webkit-examples.zip"', error); defer.reject(error); }); unzipper.on('extract', function () { _this.yeoman.log.ok('Examples successfully unzipped'); defer.resolve(); }); unzipper.extract({ path: 'tmp' }); } else { defer.resolve(); } return defer.promise; };
decompressZip: function (serialCb) { var unzipper = new DecompressZip(tmpPath); library.logger.info(dapp.transactionId, 'Decompressing zip file'); unzipper.on('error', function (err) { library.logger.error(dapp.transactionId, 'Decompression failed: ' + err.message); fs.exists(tmpPath, function (exists) { if (exists) { fs.unlink(tmpPath); } return setImmediate(serialCb, 'Failed to decompress zip file'); }); }); unzipper.on('extract', function (log) { library.logger.info(dapp.transactionId, 'Finished extracting'); fs.exists(tmpPath, function (exists) { if (exists) { fs.unlink(tmpPath); } return setImmediate(serialCb, null); }); }); unzipper.on('progress', function (fileIndex, fileCount) { library.logger.info(dapp.transactionId, ['Extracted file', (fileIndex + 1), 'of', fileCount].join(' ')); }); unzipper.extract({ path: dappPath, strip: 1 }); }
module.exports = function(zipFile, outputPath) { var deferred = Q.defer(); events.emit("log", "unzipping file: " + zipFile); var unzipper = new decompressZip(zipFile) unzipper.on('error', function (err) { events.emit("log", "unzip failed: " + err); deferred.reject(new Error("Failed to unzip file: " + zipFile)); }); unzipper.on('extract', function (log) { events.emit("log", "unzip completed."); deferred.resolve(outputPath); }); unzipper.on('progress', function (fileIndex, fileCount) { // events.emit("log", 'Extracted file ' + (fileIndex + 1) + ' of ' + fileCount); }); unzipper.extract({ path: outputPath }); return deferred.promise; }
_extract: function _extract(platform, extension) { var _this = this; var defer = when.defer(); if ('.zip' === extension) { if (fs.existsSync('tmp/' + platform + extension)) { this.log.info('Unzip %s files.', platform); var unzipper = new DecompressZip('tmp/' + platform + extension); unzipper.on('error', function (error) { _this.log.conflict('Error while unzipping "tmp/' + platform + extension + '"', error); defer.reject(error); }); unzipper.on('extract', function () { _this.log.ok('"tmp/%s.zip" successfully unzipped', platform); if (fs.existsSync('resources/node-webkit/' + platform + '/nwjs.app')) { fs.renameSync('resources/node-webkit/' + platform + '/nwjs.app', 'resources/node-webkit/' + platform + '/node-webkit.app'); } defer.resolve(); }); var stripLevel = 0; if ('MacOS64' === platform || this.nodeWebkitVersion.indexOf('v0.9.') === -1 && this.nodeWebkitVersion.indexOf('v0.8.') === -1) { stripLevel = 1; } unzipper.extract({ path: 'resources/node-webkit/' + platform, strip: stripLevel }); } else { defer.resolve(); } } else if ('.tar.gz' === extension) { this.log.info('Un.tar.gz %s files.', platform); var src = 'tmp/' + platform + extension; var dst = 'resources/node-webkit/' + platform; fs.createReadStream(src).pipe(zlib.createGunzip()).pipe(tar.extract(dst)).on('finish', function (error) { if (!error) { var platformSuffix = platform === 'Linux64' ? '-linux-x64' : '-linux-ia32'; var namePart = '/nwjs-'; if (_this.nodeWebkitVersion.indexOf('v0.9.') !== -1 || _this.nodeWebkitVersion.indexOf('v0.8.') !== -1 || _this.nodeWebkitVersion.indexOf('v0.10.') !== -1 || _this.nodeWebkitVersion.indexOf('v0.11.') !== -1) { namePart = '/node-webkit-'; } var copyPath = 'resources/node-webkit/' + platform + namePart + _this.nodeWebkitVersion + platformSuffix; fs.copy(copyPath, 'resources/node-webkit/' + platform, function(error) { if (error) { defer.reject(error); } else { fs.remove(copyPath); _this.log.ok('%s directory successfully copied.', platform); defer.resolve(); } }); } else { defer.reject(error); } }); } return defer.promise; }
function(platform, localcallback) { grunt.log.ok("Extracting " + platform); wrench.rmdirSyncRecursive(path.join(options.build_dir, platform, "atom-shell"), true); wrench.mkdirSyncRecursive(path.join(options.build_dir, platform)); var zipPath = path.join(options.cache_dir, "atom-shell-" + options.atom_shell_version + "-" + platform + ".zip"); var destPath = path.join(options.build_dir, platform, "atom-shell"); if (process.platform != 'win32' && platform == 'darwin') { spawn = require('child_process').spawn; zip = spawn('unzip',['-qq','-o', zipPath, '-d', destPath]); zip.on('exit', function(code) { localcallback(null); }); zip.stdout.on('data', function(data) { }); zip.stderr.on('data', function(data) { }); zip.on('error', function(err){ grunt.log.error(err); localcallback(err); }); } else { var unzipper = new decompressZip(zipPath); unzipper.on('error', function(err) { grunt.log.error(err); localcallback(err); }); unzipper.on('extract', function(log){ localcallback(); }); unzipper.extract({ path: destPath }); } }, function(err) { callback(err,options); }
module.exports = function(file, new_path, cb) { var error, result, zip = new DecompressZip(file); var done = function(err, res) { if (err || q.length() == 0) return cb && cb(err, res); debug('Done. Found ' + q.length() + ' elements in queue!'); result = res; // store result so we can return it when queue finishes q.resume(); } var q = queue(function (task, callback) { var file = path.join(new_path, task.file); debug('Chmodding ' + file + ' to ' + task.mode); chmod(file, task.mode, function(err) { if (err) debug(err); callback(); }); }, 2); // called when the queue reaches zero, meaning all the work is done q.drain = function() { return cb && cb(error, result); } q.pause(); // the queue will begin when the files are extracted, not before zip.on('file', function(file) { // console.log(file.path); if (!is_windows && file.type == 'File' && file.path.indexOf('node_modules') == -1) { var mode = octal(file.mode, 4); if (mode != '0644') { debug('Queueing mode set for ' + file.path) q.push({ file: file.path, mode: mode }); } } }); zip.on('extract', function(result) { done(null, result); }); zip.on('error', function(err) { done(err); }); zip.extract({ path : path.resolve(new_path), filter : function (file) { return skip_files.indexOf(file.filename) == -1; // return file.type !== "SymbolicLink"; } }); }
return when.promise(function(resolve, reject) { var unzipper = new DecompressZip(xpiPath); unzipper.on("extract", resolve); unzipper.on("error", reject); unzipper.extract({ path: outputDir, }); });
return new Promise((resolve, reject) => { var unzipper = new DZip(archivePath); unzipper.on('error', reject); unzipper.on('extract', resolve); unzipper.extract({ path: openedPath, strip: 1 }); });
new Promise(function(resolve, reject) { var unzipper = new DecompressZip(tmpFile); unzipper.on('error', reject); unzipper.on('extract', resolve); unzipper.extract({ path: tmpDir }); })
.then(function() { var unzipper = new DecompressZip(src); unzipper.on('error', function (err) { defer.reject(err); }); unzipper.on('extract', function () { defer.resolve(true); }); unzipper.extract({ path: dir }); return defer.promise; });
function makeFile(tpl, projectRoot) { let zipFile = path.join(npxRoot, 'template/' + tpl + '.zip') let unzipper = new DecompressZip(zipFile) unzipper.on('error', err => { throw new Error(err) }) unzipper.on('extract', () => { console.log(colors.bgGreen(`[task ${leftPad('create', 12)}]`), 'done') }) unzipper.extract({ path: projectRoot }) }
function processFile(e, response, body){ if(response && response.statusCode != 200){ cb(new Error('Couldn\'t download files')); } console.log(agency_key + ': Download successful'); var unzipper = new DecompressZip(downloadDir + '/latest.zip'); unzipper.on('error', handleError); // It's a bit curious why I don't call cb directly. Extract provides the function // with a variable. Node just assumes the first poarameter is an error, if present. unzipper.on('extract', function(log) { cb(); }); unzipper.extract({ path: downloadDir }); }
/** * Extracts the package into the given directory and then validates it. * * @param {string} zipPath path to package zip file * @param {string} extractDir directory to extract package into * @param {Object} options validation options * @param {function(Error, {errors: Array, metadata: Object, commonPrefix: string, extractDir: string})} callback function to call with the result */ function extractAndValidateFiles(zipPath, extractDir, options, callback) { var unzipper = new DecompressZip(zipPath); unzipper.on("error", function (err) { // General error to report for problems reading the file callback(null, { errors: [[Errors.INVALID_ZIP_FILE, zipPath, err]] }); return; }); unzipper.on("extract", function (log) { findCommonPrefix(extractDir, function (err, commonPrefix) { if (err) { callback(err, null); return; } var packageJSON = path.join(extractDir, commonPrefix, "package.json"); validatePackageJSON(zipPath, packageJSON, options, function (err, errors, metadata) { if (err) { callback(err, null); return; } var mainJS = path.join(extractDir, commonPrefix, "main.js"), isTheme = metadata && metadata.theme; // Throw missing main.js file only for non-theme extensions if (!isTheme && !fs.existsSync(mainJS)) { errors.push([Errors.MISSING_MAIN, zipPath, mainJS]); } performNpmInstallIfRequired({ production: true, proxy: options.proxy }, { errors: errors, metadata: metadata, commonPrefix: commonPrefix, extractDir: extractDir }, callback); }); }); }); unzipper.extract({ path: extractDir, filter: function (file) { return file.type !== "SymbolicLink"; } }); }
utils.generateZipFile(files, _evt).then(function(nwfile) { var unzipper = new DecompressZip(nwfile); unzipper.on('list', function (files) { t.deepEqual(expected, files); }); unzipper.list(); });
var unzip = function() { var defer = Q.defer(); var unzipper = new DecompressZip(path.join(config.folder, config.datafile)); var bar; unzipper .on('progress', function (fileIndex, fileCount) { if (typeof bar === 'undefined') { bar = new ProgressBar('Extracting', fileCount); } if (bar) { bar.tick(); } }) .on('extract', function (log) { defer.resolve(); }) .on('error', function (err) { console.log(err); }); unzipper.extract({ path: path.join(config.folder, config.folder_files) }); return defer.promise; };
.pipe(es.map(function(data, cb){ var spawn = require('child_process').spawn, dest = data.history[0].replace(new RegExp('\\' + path.extname(data.history[0]) + '$'), path.sep), unzip = spawn('unzip', ['-qq', '-o', data.history[0], '-d', dest]); if(process.platform === 'win32'){ var decompressZip = require('decompress-zip'); unzip = new decompressZip(data.history[0]); unzip .on('error', function(err) { cb(err); }) .on('extract', function(log){ cb(); }); unzip.extract({path: dest}); }else{ unzip .on('exit', function(code){ cb(); }) .on('error', function(error){ cb(error); }); } }));
/** * Extracts the package into the given directory and then validates it. * * @param {string} zipPath path to package zip file * @param {string} extractDir directory to extract package into * @param {Object} options validation options * @param {function(Error, {errors: Array, metadata: Object, commonPrefix: string, extractDir: string})} callback function to call with the result */ function extractAndValidateFiles(zipPath, extractDir, options, callback) { var callbackCalled = false; var metadata; var foundMainIn = null; var unzipper = new DecompressZip(zipPath); unzipper.on("error", function (err) { // General error to report for problems reading the file callback(null, { errors: [[Errors.INVALID_ZIP_FILE, zipPath]] }); return; }); unzipper.on("extract", function (log) { findCommonPrefix(extractDir, function (err, commonPrefix) { if (err) { callback(err, null); return; } var packageJSON = path.join(extractDir, commonPrefix, "package.json"); validatePackageJSON(zipPath, packageJSON, options, function (err, errors, metadata) { if (err) { callback(err, null); return; } var mainJS = path.join(extractDir, commonPrefix, "main.js"); if (!fs.existsSync(mainJS)) { errors.push([Errors.MISSING_MAIN, zipPath, mainJS]); } callback(null, { errors: errors, metadata: metadata, commonPrefix: commonPrefix, extractDir: extractDir }); }); }); }); unzipper.extract({ path: extractDir, filter: function (file) { return file.type !== "SymbolicLink"; } }); }
function doExpansion(source, destination, complete) { console.log("Unpacking", source); var unzipper = new DecompressZip(source); unzipper.on("error", function (err) { console.error("Problem unpacking", source); console.error(err); complete(); }); unzipper.on("extract", function () { console.log("Extraction complete"); complete(); }); unzipper.extract({ path: destination }); }
NodeWebkitGenerator.prototype._extract = function _extract(platform, extension) { var _this = this; var defer = when.defer(); if ('.zip' === extension) { if (fs.existsSync('tmp/' + platform + extension)) { this.log.info('Unzip %s files.', platform); var unzipper = new DecompressZip('tmp/' + platform + extension); unzipper.on('error', function (error) { _this.log.conflict('Error while unzipping "tmp/' + platform + extension + '"', error); defer.reject(error); }); unzipper.on('extract', function () { _this.log.ok('"tmp/%s.zip" successfully unzipped', platform); defer.resolve(); }); unzipper.extract({ path: 'resources/node-webkit/' + platform }); } else { defer.resolve(); } } else if ('.tar.gz' === extension) { this.log.info('Un.tar.gz %s files.', platform); var src = 'tmp/' + platform + extension; var dst = 'resources/node-webkit/' + platform; fs.createReadStream(src).pipe(zlib.createGunzip()).pipe(tar.extract(dst)).on('finish', function (error) { if (!error) { fs.copy('resources/node-webkit/' + platform + '/node-webkit-'+ _this.nodeWebkitVersion +'-linux-x64', 'resources/node-webkit/' + platform, function (error) { if (error) { defer.reject(error); } else { fs.remove('resources/node-webkit/' + platform + '/node-webkit-'+ _this.nodeWebkitVersion +'-linux-x64'); _this.log.ok('%s directory successfully copied.', platform); defer.resolve(); } }); } else { defer.reject(error); } }); } return defer.promise; };
module.exports = function (file, callback){ var data = {}; var unzipper = new decompress(file); unzipper.extract({ path: output.path }); unzipper.on('error', cleanUp); unzipper.on('extract', function() { var path = glob.sync(output.path + '/Payload/*/')[0]; data.metadata = plist.parse(fs.readFileSync(path + 'Info.plist', 'utf8')); if(!fs.existsSync(path + 'embedded.mobileprovision') || !which.sync('security')){ return cleanUp(); } exec('security cms -D -i embedded.mobileprovision > ' + provisionFilename, { cwd: path }, function(error) { if(error){ cleanUp(error); } data.provisioning = plist.parse(fs.readFileSync(path + provisionFilename, 'utf8')); delete data.provisioning.DeveloperCertificates; if(!which.sync('codesign')){ return cleanUp(); } exec('codesign -d --entitlements :- ' + path, function(error, output) { data.entitlements = plist.parse(output); return cleanUp(); }); }); }); function cleanUp(error){ rimraf.sync(output.path); return callback(error, data); } };
req.file('avatar').upload(function (err, files) { if (err) return res.serverError(err); //console.log(files); //base dir: /avior-service //console.log(fs.readdirSync('./.tmp/uploads')); var fs = require('fs'); if(files[0].type === "application/zip"){ console.log(".zip file found, starting integration..."); fs.renameSync('./.tmp/uploads/' + files[0].filename, './api/hooks/plugins/zipped/' + files[0].filename); var DecompressZip = require('decompress-zip'); var unzipper = new DecompressZip('./api/hooks/plugins/zipped/' + files[0].filename) unzipper.on('error', function (err) { console.log('Caught an error: ' + err); }); unzipper.on('extract', function (log) { console.log('Finished extracting to /api/hooks/plugins/files/'); }); unzipper.extract({ path: './api/hooks/plugins/files/', filter: function (file) { return file.type !== "SymbolicLink"; } }); return res.json({ message: files.length + ' file(s) uploaded successfully!', files: files }); } else{ console.log("Please upload a .zip file containing your files."); return res.json({ error: "Not a .zip file." }); } });
tmp.dir(function(err, tmpPath, removeTmpDir) { function cleanUpAndReject(err) { removeTmpDir(); reject(err); } if (err) { return cleanUpAndReject(err); } var unzipper = new DecompressZip(xpiPath); unzipper.on("extract", function(_log) { resolve({ path: tmpPath, remove: removeTmpDir, }); }); unzipper.on("error", cleanUpAndReject); unzipper.extract({ path: tmpPath, }); }, {
const ExtractZip = (path, destination, callback) => { const unzip = new DecompressZip(path); unzip.on('error', (err) => callback(err)) .on('extract', () => callback(null, destination)) .extract({ path: destination, // Ignore the root directory. strip: 1 }); };
var extractZipArtifact = function(cb) { if (fs.existsSync(self.kgData.executable)) { LogService.trace("%s already exists, skipping extraction", self.kgData.executable); cb(); return; } LogService.trace("Extracting %s to %s", self.kgData.archive, self.kgData.extractDir); var unzipper = new DecompressZip(self.kgData.archive); unzipper.on('error', function(err) { LogService.error('Error unzipping %s: ', self.kgData.archive, err); }); unzipper.on('extract', function (log) { LogService.trace('finished extraction: ', log); cb(); }); unzipper.extract({ path: self.kgData.extractDir }); };
this.init = function(file) { var unzipper = new DecompressZip('downloads/'+file) unzipper.on('error', function (err) { evt.emit('onExtractError', err); }); unzipper.on('extract', function (log) { var filePath = ""; log.forEach(function(obj) { if (obj['deflated']) { if (obj['deflated'].indexOf(fileNameMatch) >= 0) { filePath = obj['deflated']; } } }); if (filePath.length == 0) { evt.emit('onExtractError', 'No file name match'); return; }; evt.emit('onExtractComplete', filePath) }); unzipper.on('progress', function (fileIndex, fileCount) { console.log('Extracted file ' + (fileIndex + 1) + ' of ' + fileCount); }); unzipper.extract({ path: 'extracted', filter: function (file) { return file.type !== "SymbolicLink"; } }); }
utils.generateZipFile(files, _evt, expectedPackage).then(function(nwfile) { var unzipper = new DecompressZip(nwfile), unzipDestination = 'test/temp/platform-specific-unzipped'; unzipper.on('extract', function (log) { t.equal(fs.readFileSync(path.join(unzipDestination, 'package.json')).toString(), expectedPackage); t.end(); }); unzipper.extract({ path: unzipDestination }); });
PluginManager.prototype.unzipPackage = function () { var self=this; var defer=libQ.defer(); var extractFolder='/tmp/downloadedPlugin'; var unzipper = new DecompressZip('/tmp/downloaded_plugin.zip') unzipper.on('error', function (err) { console.log("ERROR: "+err); defer.reject(new Error()); }); unzipper.on('extract', function (log) { defer.resolve(extractFolder); }); unzipper.extract({ path: extractFolder }); return defer.promise; }
gulp.task( 'client:nw-unpackage', function( cb ) { var releaseDir = getReleaseDir(); var base = path.join( releaseDir, config.platformArch ); var packagePath = path.join( releaseDir, config.platformArch + '-package.zip' ) if ( config.platform != 'osx' ) { fs.renameSync( path.join( base, 'package.nw' ), packagePath ); var DecompressZip = require( 'decompress-zip' ); var unzipper = new DecompressZip( packagePath ); unzipper.on( 'error', cb ); unzipper.on( 'extract', function() { var stream = gulp.src( base + '/package/**/*' ) .pipe( plugins.tar( config.platformArch + '-package.tar' ) ) .pipe( plugins.gzip() ) .pipe( gulp.dest( releaseDir ) ); stream.on( 'error', cb ); stream.on( 'end', function() { mv( path.join( base, 'package', 'node_modules' ), path.join( base, 'node_modules' ), function( err ) { if ( err ) { throw err; } mv( path.join( base, 'package', 'package.json' ), path.join( base, 'package.json' ), function( err ) { if ( err ) { throw err; } cb(); } ); } ); } ); } ); unzipper.extract( { path: path.join( base, 'package' ) } ); } else { var stream = gulp.src( base + '/Game Jolt Client.app/Contents/Resources/app.nw/**/*' ) .pipe( plugins.tar( config.platformArch + '-package.tar' ) ) .pipe( plugins.gzip() ) .pipe( gulp.dest( releaseDir ) ); stream.on( 'end', cb ); stream.on( 'error', cb ); } } );
tools.unzipFile = function(archive, dest) { var deferred = Q.defer(); var unzipper = new DecompressZip(archive); unzipper.on('error', function(err) { deferred.reject(err); }); unzipper.on('extract', function() { deferred.resolve(dest); }); // unzipper.on('progress', function(index, count) { // }); unzipper.extract({ path: dest, filter: function(file) { return file.type !== 'SymbolicLink'; } }); return deferred.promise; };