Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
fs.readFile(settings.folder + "/" + file, function(err,data) {
if (err) {
//crapout(err);
console.log(" - ERROR reading file prior to save: " + settings.folder + "/" + file);
deferred2.resolve(settings.folder + "/" + file);
} else {
itob.isText(file,data,function (err,result) {
if (result) {
data = data.toString(); // convert to string if utf8, otherwise leave as binary buffer
}
// actually upload the file once working
var vf = settings.folder;
if (settings.stripBaseFolder) {
vf = settings.folder.substring(base.length + 1);
}
/*if (0 == vf.indexOf("/")) {
vf = vf.substring(1);
}*/
if (0 != vf.indexOf("/") && vf.length != 0) {
vf = "/" + vf;
}
return new Promise((resolve, reject) => {
_isText(filename, buffer, (err: Error, result: boolean) => {
if (err) {
return reject(err);
}
// We don't support null bytes in the database with postgres,
// so we need to mark it as binary if there are null bytes
const hasNullByte = buffer.toString().includes("\0");
resolve(
result &&
!FILE_LOADER_REGEX.test(filename) &&
!isTooBig(buffer) &&
!hasNullByte
);
});
});
return new Promise((resolve, reject) => {
isTextOrBinary.isText(Path.basename(file.path), file.contents, (err, isText) => {
if (err) return reject(err);
if (isText) file.isText = true;
resolve(file);
});
});
}
function normalizeFile(path) {
const stream = fs.createReadStream(path);
if (isText(path, stream)) {
const normalizeNewline = streamNormalizeEol('\n');
return stream.pipe(normalizeNewline);
} else {
return stream;
}
}
result = result.join('');
}
else {
result = chunks.join(replacement);
}
file.contents = new Buffer(result);
}
return callback(null, file);
}
callback(null, file);
}
if (options && options.skipBinary) {
istextorbinary.isText(file.path, file.contents, function(err, result) {
if (err) {
return callback(err, file);
}
if (!result) {
callback(null, file);
} else {
doReplace();
}
});
return;
}
doReplace();
}
function normalizeFile(path) {
const stream = fs.createReadStream(path);
if (isText(path, stream)) {
const normalizeNewline = normalizeEol('\n');
return stream.pipe(normalizeNewline);
} else {
return stream;
}
}