Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
out.on("close", callback);
// Use zlib compression 1 (fastest) to overcome a bug currently in Archiver on Macs
zip = archiver('zip', {zlib: {level: 1}});
zip.on('error', function(err) {
throw err;
});
zip.pipe(out);
for(var i = 0, ln = files.length; i < ln; i++) {
var file = files[i],
filename = config.tishadow_src + '/' + file,
stream;
// Lazy load streams, to counteract 'too many files' error on Node
// Lazystream only creates the actual ReadStream when a read command is received
stream = new lazystream.Readable(function (options) {
return fs.createReadStream(this.filename);
});
stream.filename = filename;
zip.append(stream, {name : files[i]});
}
zip.finalize();
};
function lazyObjectReadable(fn: () => Readable) {
const lazyStream = new lazystream.Readable(
() => {
try {
return fn();
} catch (ex) {
lazyStream.emit('error', ex);
return emptyReadable();
}
},
{ objectMode: true },
);
return lazyStream;
}
function streamFile(file, opt, cb) {
if (typeof opt === 'function') {
cb = opt;
opt = {};
}
var filePath = file.path;
file.contents = new lazystream.Readable(function() {
return fs.createReadStream(filePath);
});
if (opt.stripBOM) {
file.contents = file.contents.pipe(stripBom());
}
cb(null, file);
}
function streamFile(file, optResolver, onRead) {
if (typeof optResolver === 'function') {
onRead = optResolver;
optResolver = createResolver();
}
var filePath = file.path;
var removeBOM = optResolver.resolve('removeBOM', file);
file.contents = new lazystream.Readable(function() {
var contents = fs.createReadStream(filePath);
if (removeBOM) {
return contents.pipe(removeBomStream());
}
return contents;
});
onRead();
}
function streamFile(file, opt, cb) {
if (typeof opt === 'function') {
cb = opt;
opt = {};
}
var filePath = file.path;
file.contents = new lazystream.Readable(function() {
return fs.createReadStream(filePath);
});
if (opt.stripBOM) {
file.contents = file.contents.pipe(stripBom());
}
cb(null, file);
}
files.forEach(function(srcFile) {
var srcStream = new Readable(function() {
return fs.createReadStream(srcFile.src);
});
archive.append(srcStream, { name: srcFile.dest }, function(err) {
grunt.verbose.writeln('Archiving ' + srcFile.src + ' -> ' + '/' + srcFile.dest.cyan);
});
});