Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
exports.tar = function(files, done) {
if (typeof exports.options.archive !== 'string' || exports.options.archive.length === 0) {
grunt.fail.warn('Unable to compress; no valid archive file was specified.');
return;
}
var mode = exports.options.mode;
if (mode === 'tgz') {
mode = 'tar';
exports.options.gzip = true;
}
var archive = archiver.create(mode, exports.options);
var dest = exports.options.archive;
var dataWhitelist = ['comment', 'date', 'mode', 'store', 'gid', 'uid'];
var sourcePaths = {};
// Ensure dest folder exists
grunt.file.mkdir(path.dirname(dest));
// Where to write the file
var destStream = fs.createWriteStream(dest);
archive.on('error', function(err) {
grunt.log.error(err);
grunt.fail.warn('Archiving failed.');
});
function createLambda(role, llamaFile, done) {
var lambda = new aws.Lambda({apiVersion: '2015-03-31'});
var archive = archiver.create('zip', {});
var lambdaPath = path.join(__dirname, '../../lambda/index.js');
var tmpf = tmp.fileSync();
var tmpfStream = fs.createWriteStream(tmpf.name);
archive.pipe(tmpfStream);
archive.append(fs.readFileSync(lambdaPath), { name: 'index.js' });
if (llamaFile) {
debug('Adding real Chaosfile to lambda zip');
llamaFile.region = process.env.AWS_REGION; // FIXME
archive.append(new Buffer(JSON.stringify(llamaFile)), { name: 'config.json' });
} else {
debug('Adding a stub Chaosfile to lambda zip');
archive.append(new Buffer(JSON.stringify({enableForASGs: []})), { name: 'config.json' });
}
lambdaDependencies.forEach( function (moduleName){
archive.directory(path.join(__dirname, '..', '..', './node_modules/' + moduleName), 'node_modules/'+ moduleName);
async streamZipDataTo(params, callback) {
let zip = new Archiver.create('zip') //eslint-disable-line new-cap
if (params.pipe) zip.pipe(params.pipe)
// Set response headers
params.pipe.writeHeader(200, {
'Content-Type': 'application/zip',
"Content-disposition": 'attachment; filename=camp-files.zip'
})
let self = this
let fileList = await this.listBucket(params.bucket, params.prefix)
let fileArr = fileList.Contents.map(async (file) => {
let fileList = []
let fileObj = await self.getObject(params.bucket, file.Key)
let name = self.calculateFileName(file)
deployer.deployController = function( environmentConfig, controllerName, controllerConfig, directoryPath, indexCommand, isUpdate, awsCredentials, callback ){
AWS.config.update({
accessKeyId: awsCredentials.awsAccessKey,
secretAccessKey : awsCredentials.awsSecretAccessKey,
region : awsCredentials.regionName
});
// Create a temp folder to store the zip until upload is complete
mkdirp.sync('./temp');
var outZip = fs.createWriteStream('./temp/lambda.zip' )
var archive = archiver.create('zip',{});
archive.append( indexCommand, { name: 'index.js' } );
// Zip the controller directory, but inside the zip put it in a '/run' subdirectory.
archive.directory('./controllers/' + controllerName, '/run' );
archive.pipe( outZip );
archive.finalize();
outZip.on('close', function(){
var lambda = new AWS.Lambda();
var params = {
FunctionName: 'hocus_' + environmentConfig.id + '_controller_' + controllerName,
};
if ( isUpdate ){
export async function downloadSeriesItemAsync(series: mio.IScraperSeries, seriesChapter: mio.IScraperSeriesChapter) {
let chapterPath = shared.path.normal(series.providerName, series.title, seriesChapter.name + shared.extension.cbz);
let chapterExists = await fs.pathExists(chapterPath);
if (!chapterExists) {
console.log(`Fetching ${seriesChapter.name}`);
let chapter = archiver.create('zip', {store: true});
let timer = new mio.Timer();
await fs.ensureDir(path.dirname(chapterPath));
chapter.pipe(fs.createWriteStream(chapterPath + shared.extension.tmp));
await mio.usingAsync(seriesChapter.iteratorAsync(), async iterator => {
try {
await archiveAsync(chapter, iterator);
chapter.finalize();
await fs.rename(chapterPath + shared.extension.tmp, chapterPath);
console.log(`Finished ${seriesChapter.name} (${timer})`);
} catch (error) {
await fs.unlink(chapterPath + shared.extension.tmp);
throw error;
} finally {
chapter.abort();
}
});
function createTarStream (callback) {
var tarStream = archiver.create('tar', { gzip: true })
tarStream.bulk([{ expand: true, cwd: pkgRoot, src: ['**', '!node_modules/**'] }])
tarStream.finalize()
callback(null, tarStream)
}
await new Promise((resolve, reject) => {
let zipStream = fs.createWriteStream(zipArchivePath);
zipStream.on('close', () => resolve());
let archive = archiver.create('zip', {});
archive.on('error', e => reject({ Error: e }));
archive.pipe(zipStream);
archive.glob('**', { dot: true, cwd: tmpDir, ignore: options.zipFileName });
archive.finalize();
});
function createZipfile(files) {
var zip = archiver.create('zip', {});
for (var i = 0; i < files.length; i++) {
var file = files[i]
zip.append(file.data, {'name': file.name});
}
return zip;
}
let tempContentYmlFilePath = pathManager.getBackendBuildYamlFilePath(projectInfo.ProjectPath)
let contentZipFilePath = pathManager.getBackendContentZipFilePath(projectInfo.ProjectPath)
let zipInternalFilePath = 'awsmobile-cli-project/' + awsmobileJSConstant.BackendProjectYamlFileName
awsMobileYamlOps.writeYamlFileSync(backendProjectSpec, tempContentYmlFilePath)
let output = fs.createWriteStream(contentZipFilePath)
output.on('close', function() {
fs.removeSync(tempContentYmlFilePath)
if(callback){
callback()
}
})
let zip = archiver.create('zip', {})
zip.pipe(output)
zip.append(fs.createReadStream(tempContentYmlFilePath), {name: zipInternalFilePath})
zip.finalize()
}