Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
this.relativeDir = relativefileInfo.dir;
this.pathSegments = _.compact(this.path.split('/'));
this.depth = this.pathSegments.length;
this.modified = this.stat.mtime;
this.order = nameParts ? parseInt(nameParts[1], 10) : 10000; // Can't use Infinity as it converts to NULL on JSON stringification!
this.hidden = !! _.find(this.pathSegments, function(segment){
return segment.charAt(0) === '_';
});
if (this.isFile()) {
this.raw = this.contents;
this.lang = this.ext.replace(/^\./,'').toLowerCase();
this.isBinary = tob.isBinarySync(this.relativePath, this.contents);
}
return this;
};
copy(source, dest) {
dest = dest || source;
source = this.templatePath(source);
var headers = readChunk.sync(source, 0, 512);
if (istextorbinary.isBinarySync(undefined, headers)) {
this.fs.copy(source, this.destinationPath(dest));
} else {
this.template(source, dest);
}
}
exports.isBinary = (existingFilePath, newFileContents) => {
const existingHeader = readChunk.sync(existingFilePath, 0, 512);
return (
istextorbinary.isBinarySync(existingFilePath, existingHeader) ||
(newFileContents && istextorbinary.isBinarySync(existingFilePath, newFileContents))
);
};
function isBinary(contentType, buffer) {
let type = getResourceType(contentType);
//TODO Image is not always binary (SVG)
if (type === 'Image' || type === 'Media' || type === 'Font') {
return true;
}
if (type === 'Other' && isTextOrBinary.isBinarySync(buffer)) {
return true;
}
return false;
}
function isBinary(contentType, buffer) {
let type = getResourceType(contentType);
//TODO Image is not always binary (SVG)
if (type === 'Image' || type === 'Media' || type === 'Font') {
return true;
}
if (type === 'Other' && isTextOrBinary.isBinarySync(buffer)) {
return true;
}
return false;
}
function run(file, done) {
if (
isTextOrBinary.isBinarySync(path.basename(file), files[file].contents)
) {
done();
return;
}
let str = files[file].contents.toString();
render(str, metadata, function(err, res) {
if (err) {
return done(err);
}
files[file].contents = new Buffer(res);
done();
});
}
}
actions.copy = function copy(source, dest) {
dest = dest || source;
source = this.templatePath(source);
var headers = readChunk.sync(source, 0, 512);
if (istextorbinary.isBinarySync(undefined, headers)) {
this.fs.copy(source, this.destinationPath(dest));
} else {
this.template(source, dest);
}
return this;
};