Рефакторинг

This commit is contained in:
Book Pauk
2020-02-06 20:13:33 +07:00
parent 65c1227d88
commit 29082a10e6
2 changed files with 21 additions and 12 deletions

View File

@@ -1,6 +1,5 @@
const fs = require('fs-extra');
const iconv = require('iconv-lite');
const chardet = require('chardet');
const he = require('he');
const LimitedQueue = require('../../LimitedQueue');
@@ -77,16 +76,6 @@ class ConvertBase {
decode(data) {
let selected = textUtils.getEncoding(data);
if (selected == 'ISO-8859-5') {
const charsetAll = chardet.detectAll(data.slice(0, 20000));
for (const charset of charsetAll) {
if (charset.name.indexOf('ISO-8859') < 0) {
selected = charset.name;
break;
}
}
}
if (selected.toLowerCase() != 'utf-8')
return iconv.decode(data, selected);
else

View File

@@ -1,4 +1,23 @@
function getEncoding(buf, returnAll) {
const chardet = require('chardet');
function getEncoding(buf) {
let selected = getEncodingLite(buf);
if (selected == 'ISO-8859-5') {
const charsetAll = chardet.detectAll(buf.slice(0, 20000));
for (const charset of charsetAll) {
if (charset.name.indexOf('ISO-8859') < 0) {
selected = charset.name;
break;
}
}
}
return selected;
}
function getEncodingLite(buf, returnAll) {
const lowerCase = 3;
const upperCase = 1;
@@ -106,5 +125,6 @@ function checkIfText(buf) {
module.exports = {
getEncoding,
getEncodingLite,
checkIfText,
}