Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
.on('finish', () => {
console.log(`${output} written.`)
if (commander.unzip) {
const unzipOuput = output.replace(/\.zip\s*$/, '');
// make sure the extracting path exist and empty
shelljs.rm('-rf', unzipOuput);
shelljs.mkdir('-p', unzipOuput);
const readStream = fs.createReadStream(output);
const writeStream = fstream.Writer(unzipOuput);
readStream
.pipe(unzip.Parse())
.pipe(writeStream);
}
});
});
var invokeInNew = function(command, directory, options, fn) {
// copy directory into newApps
var from = path.resolve(path.join('spec', 'support', 'apps', directory));
var to = path.resolve(path.join('spec', 'support', 'apps', 'new_apps', directory));
wrench.mkdirSyncRecursive(to);
var reader = fstream.Reader(from);
var writer = fstream.Writer(to);
writer.on('close', function() {
invoke(command, path.join('new_apps', directory), options, fn);
});
reader.pipe(writer);
}
return new Promise((resolve, reject) => {
var dest = fstream.Writer({ path: destination });
dest.on("close", function(ex) {
resolve(tempPath);
});
fstream.Reader({ path: tempPath, type: 'Directory' }) /* Read the source directory */
.pipe(tar.Pack()) /* Convert the directory to a .tar file */
.pipe(zlib.Gzip()) /* Compress the .tar file */
.pipe(dest); /* Give the output file name */
});
},
.on('entry', (entry: any) => {
entry.path = entry.path.replace('unpackaged/', '');
entry.pipe(fstream.Writer({
type: entry.type,
path: target + entry.path
}))
.on('end', () => { resolve(true); }) // Finished
.on('error', (err: any) => { reject(err); });
});
});
function onFinally() {
if (fs.existsSync(fileBackupDirectory)) {
fs.removeSync(fileBackupDirectory);
}
if (fs.existsSync(tmpName)) {
fs.removeSync(tmpName);
}
}
var installedDirectoryStream = fstream.Reader({path: installedDirectory}).on('error', onError);
// TODO: speed this up
if (this.config.noArchive) {
installedDirectoryStream
.on('end', onEnd)
.pipe(fstream.Writer({path: tmpName, type: 'Directory'}));
} else {
tar.pack(installedDirectory)
.pipe(zlib.createGzip())
.pipe(fs.createWriteStream(tmpName))
.on('error', onError)
.on('finish', onEnd);
}
};
function unzip_file(zip, path, file, check, size, i) {
var readStream = fs.createReadStream(__dirname+zip[i]);
var writeStream = fstream.Writer(__dirname+path[i]);
readStream.pipe(unzip.Parse()).pipe(writeStream);
writeStream.on('close', function () {
check(__dirname+file[i]);
if ((i + 1) < size)
unzip_file(zip, path, file, check, size, (i + 1));
//else do_stuff();
});
console.log("File " + file[i] + " extracted to " + path[i]);
}
})
.on('close', function () {
tarball.emit('close')
})
return
}
if (type === 'naked-file' && defaultName) {
var jsOpts = { path: path.resolve(target, defaultName) }
if (!win32 && typeof uid === 'number' && typeof gid === 'number') {
jsOpts.uid = uid
jsOpts.gid = gid
}
strm
.pipe(fstream.Writer(jsOpts))
.on('error', function (er) {
if (er) debug('copy error')
tarball.emit('error', er)
})
.on('close', function () {
tarball.emit('close')
})
return
}
return cb(new Error('Unrecognised package type'));
})
}
client.post("http://realfavicongenerator.net/api/favicon", args, function(data, response) {
if (response.statusCode !== 200) {
grunt.warn(data);
return;
}
var writeStream = fstream.Writer(dest);
var parserStream = unzip.Parse();
var request = http.get(data.favicon_generation_result.favicon.package_url, function(response) {
response.pipe(parserStream).pipe(writeStream);
});
writeStream.on('close', function() {
callback(data.favicon_generation_result);
});
});
}
return fs.rename(this.path, localPath, function (err) {
if (!err) return this.cleanUpLocal();
var writter = fstream.Writer({
type: 'Directory',
path: localPath
});
writter
.on('error', this.emit.bind(this, 'error'))
.on('end', rimraf.bind(this, this.path, this.cleanUpLocal.bind(this)));
fstream.Reader(this.path)
.on('error', this.emit.bind(this, 'error'))
.pipe(writter);
}.bind(this));
}.bind(this));
mkdirp(installedPath, function (err) {
if (err) {
return cb(err);
}
fstream.Reader(cachePath)
.pipe(fstream.Writer(installedPath))
.on('error', cb)
.on('close', function () {
link(installedPath, self.prefix, function (err) {
cb(err, installedPath, content.version);
});
});
});
});