Detect-It-Easy/db/Binary/text.plaintext.3.sg
2025-04-28 16:13:00 +03:00

26 lines
No EOL
778 B
JavaScript
Executable file

// Detect It Easy: detection rule file
init("format", "Plain text");
function detect() {
if (Binary.isPlainText()) {
var sText = Binary.getString(0, Math.min(Binary.getSize(), 3));
// UTF-8 BOM.
if (/^\xef\xbb\xbf/.test(sText)) {
sName = "UTF-8 text";
}
var size = Binary.getSize() < 4096 ? Binary.getSize() : 4096,
pos = Binary.findByte(0, size, 10);
if (pos !== -1) {
sOptions = (pos != 0 && Binary.readByte(pos - 1) == 13) || (pos + 1 < Binary.getSize() && Binary.readByte(pos + 1) == 13) ? "CRLF" : "LF";
} else if (Binary.findByte(0, size, 13) != -1) {
sOptions = "CR";
}
bDetected = true;
}
return result();
}