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);
}
});
});
TarGz.prototype.createReadStream = function(directory) {
// Create all needed streams
var stream1 = fstream.Reader(directory);
var stream2 = tar.Pack(this._options.tar);
var stream3 = zlib.createGzip(this._options.zlib);
// Bubble erros
this._bubble(stream3, stream2, stream1);
return stream1.pipe(stream2).pipe(stream3);
};
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);
}
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);
}
};
module.exports.fstreamWrite = function (callback) {
fstream.Reader(datadir)
.pipe(db.writeStream({ fstreamRoot: path.resolve(__dirname) })
.on('close', function () {
console.log('Piped data to database...')
callback()
}))
.on('error', callback)
}
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'));
})
}