Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
function gzipFile(source) {
var tempFile;
var deferred = Q.defer();
var gzip = zlib.createGzip({
level: 9 // maximum compression
});
var inp;
var out;
gzip.on('error', function (err) {
deferred.reject(err);
});
inp = fs.createReadStream(source);
tempFile = source + '.zip';
out = fs.createWriteStream(tempFile);
out.on('close', function () {
deferred.resolve(tempFile);
});
inp.pipe(gzip).pipe(out);
return deferred.promise;
}
helmet = require('helmet'),
lusca = require('lusca'),
sanitizer = require('sanitizer'),
passport = require('passport'),
med = require('./routes/meds'),
user = require('./routes/users'),
https = require('https'),
fs = require('fs'),
compression = require('compression'),
minify = require('express-minify'),
expressHbs = require('express-handlebars'),
config = require(process.env.MED_CONF);
var app = express();
var accessLogStream = fs.createWriteStream(config.accessLog, {
flags: 'a'
});
app.configure(function() {
app.set('port', process.env.PORT || 3000);
app.use(express.logger({stream: accessLogStream}));
app.use(compression());
app.use(minify());
app.use(express.bodyParser());
app.use(express.cookieParser());
app.use(express.methodOverride());
app.use(express.session({
secret: 'penandteller',
cookie: {
maxAge: 3600000 // see below
}
var request = https.get(url, function(response) {
if (response.statusCode !== 200) {
log.red('Unable to download: ' + url);
log.yellow('\nPlease download it manually and place it in ' + dest + '\n\n');
if (cb) cb(false);
} else {
var file = fs.createWriteStream(dest, {
flags: 'w'
});
response.pipe(file);
file.on('finish', function() {
log.green('Downloaded: ' + dest + '\n');
file.close(cb); // close() is async, call cb after close completes.
});
}
}).on('error', function(err) {
log.red('Unable to download: ' + url);
function bundle () {
var wb = w.bundle();
wb.on('error', function (err) {
notifyError(String(err));
var writeStream = fs.createWriteStream(outfile);
writeStream.on('error', notifyError);
writeStream.on('end', refreshServer.refresh.bind(refreshServer));
writeStream.write('window.BUNDLE_ERROR_MESSAGE = ' + JSON.stringify(String(err)) + ';\n');
writeStream.write(clientSource);
});
var writeStream = fs.createWriteStream(dotfile);
wb.pipe(writeStream);
writeStream.write(clientSource);
var bytes, time;
w.on('bytes', function (b) { bytes = b; });
w.on('time', function (t) { time = t; });
wb.on('end', function () {
fs.rename(dotfile, outfile, function (err) {
if (err) return notifyError(err);
if (verbose) {
console.error(bytes + ' bytes written to ' + outfile + ' (' + (time / 1000).toFixed(2) + ' seconds)');
}
refreshServer.refresh();
});
});
copy: function(options,config,logger){
var p = new Promise();
newFile = fs.createWriteStream(options.to),
oldFile = fs.createReadStream(options.from);
newFile.on('open',function(fd){
util.pump(oldFile,newFile, function(err){
logger.info("File " + options.from + " copied to " + options.to);
p.resolve(true);
});
});
return p;
}
};
message.attachments.forEach((checksum) => {
const file = fs.createWriteStream(`${checksum}.eml`);
request(`https://mailsac.com/api/addresses/${address}/messages/${message._id}/attachments/${checksum}`)
.pipe(file);
});
}
.then(mtime => {
let outstream = fs.createWriteStream(outpath)
outstream.mtime = mtime
return outstream
})
}
new Promise((resolve, reject) => {
const filePath = path.join(configPaths.uploadedDocuments, fileName);
const writeStream = fs.createWriteStream(filePath);
readStream.pipe(writeStream)
.on('finish', () => resolve(filePath))
.on('error', reject);
});
HTTP.get(url, response => {
let out = FS.createWriteStream(filePath);
response.pipe(out);
response.on('end', callback);
}).on('error', fail);
}
function transcodeGif(source, callback) {
var gifPath = temp.path({ suffix: '.gif' });
var gifStream = fs.createWriteStream(gifPath);
source.pipe(gifStream).on('finish', function() {
var destPath = temp.path({ suffix: '.webm' });
var ffmpeg = spawn('ffmpeg',
['-i', gifPath, '-vcodec', 'libvpx', destPath]);
metrics.streamTimer(ffmpeg, 'transcode');
ffmpeg.on('close', function(code) {
fs.unlink(gifPath);
if (code !== 0) {
callback('Failed, exit code ' + code);
return;
}
fs.stat(destPath, function(err, stats) {