Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
if (!is.nonEmptyObj(task))
return asyncerr(new Error('No task received.'), cb);
// ensure the task has a filename
if (!is.str(task.fileName))
return asyncerr(new Error('Task has no fileName: '+inspect(task)), cb);
try {
// convert array representing a buffer into a string
if (is.array(task.file))
task.file = new Buffer(task.file);
} catch(err) {
return asyncerr(err, cb);
}
// ensure we have a string representing the file
if (!is.buffer(task.file))
return asyncerr(new Error('Task has no task.file: '+
inspect(task.file)), cb);
if (!is.array(task.args))
return asyncerr(new Error('Task has no args: '+inspect(task)), cb);
task.fileName = path.normalize(task.fileName);
// we want to dump the file in /tmp. If it is starts with /tmp, fine.
if (task.fileName.substr(0,4) !== '/tmp')
task.fileName = path.join('/tmp', task.fileName);
// get the dir and make the directory
var dir = path.dirname(task.fileName);
// place the output buffers in an object, so we can pass the object
exports.writeFile = function(fileName, fileContents, cb) {
if (!is.nonEmptyStr(fileName)) {
return asyncerr(new Error('writeFile: bad fileName param: '+
inspect(fileName)), cb);
}
if (!is.nonEmptyStr(fileContents) && !is.buffer(fileContents)) {
return asyncerr(new Error('writeFile: bad fileName param: '+
inspect(fileName)), cb);
}
fs.writeFile(fileName, fileContents, function (err) {
if (err) {
debug('writeFile, could not write file: '+err.message);
return cb('writeFile, could not write file: '+err.message);
}
if (is.func(cb)) cb(null);
});
};
/**