From db4bc2afb2906c1e08ab9b2f88483a98e0cad983 Mon Sep 17 00:00:00 2001 From: Book Pauk Date: Sun, 17 Feb 2019 14:27:49 +0700 Subject: [PATCH] =?UTF-8?q?=D0=A3=D0=BB=D1=83=D1=87=D1=88=D0=B5=D0=BD?= =?UTF-8?q?=D0=B0=20=D1=8D=D0=B2=D1=80=D0=B8=D1=81=D1=82=D0=B8=D0=BA=D0=B0?= =?UTF-8?q?=20=D0=BE=D0=BF=D1=80=D0=B5=D0=B4=D0=B5=D0=BB=D0=B5=D0=BD=D0=B8?= =?UTF-8?q?=D1=8F=20=D1=82=D0=B5=D0=BA=D1=81=D1=82=D0=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- server/core/BookConverter/textUtils.js | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/server/core/BookConverter/textUtils.js b/server/core/BookConverter/textUtils.js index 316f0ec7..5713d1a7 100644 --- a/server/core/BookConverter/textUtils.js +++ b/server/core/BookConverter/textUtils.js @@ -70,13 +70,22 @@ function getEncoding(buf) { function checkIfText(buf) { let spaceCount = 0; + let crCount = 0; + let lfCount = 0; for (let i = 0; i < buf.length; i++) { if (buf[i] == 32) spaceCount++; + if (buf[i] == 13) + crCount++; + if (buf[i] == 10) + lfCount++; } - const freq = spaceCount/(buf.length + 1); - return (freq > 0.1); + const spaceFreq = spaceCount/(buf.length + 1); + const crFreq = crCount/(buf.length + 1); + const lfFreq = lfCount/(buf.length + 1); + + return (spaceFreq > 0.1 || crFreq > 0.03 || lfFreq > 0.03); } module.exports = {