Revert "try to replace html sniffing with chardet to fix ncc.html files with set encoding but strings that ignore that"

This reverts commit 3a1be51a83.

Revert "try to properly interpret ncc.html encoding (seems to be a bit weird / incorrect sometimes)"

This reverts commit fac4415595.
This commit is contained in:
Toni Barth 2026-02-08 03:33:56 +01:00
parent b05acce22b
commit 52a0b61b97
5 changed files with 3 additions and 120 deletions

View file

@ -6,8 +6,6 @@ const fs = require('../libs/fsExtra')
const rra = require('../libs/recursiveReaddirAsync')
const Logger = require('../Logger')
const { AudioMimeType } = require('./constants')
const chardet = require('chardet')
const whatwgEncoding = require('whatwg-encoding')
/**
* Make sure folder separator is POSIX for Windows file paths. e.g. "C:\Users\Abs" becomes "C:/Users/Abs"
@ -117,57 +115,15 @@ function getIno(path) {
}
module.exports.getIno = getIno
/**
* @typedef ReadTextFileOptions
*/
function detectTextEncoding(buffer) {
try {
const detectedEncoding = chardet.detect(buffer)
const labeledEncoding = detectedEncoding ? whatwgEncoding.labelToName(detectedEncoding) : null
if (labeledEncoding) {
return labeledEncoding
}
} catch {}
return 'UTF-8'
}
/**
* Decode raw text bytes with optional encoding detection.
*
* @param {Buffer} buffer
* @param {ReadTextFileOptions} [options]
* @returns {string}
*/
function decodeTextBuffer(buffer, options = {}) {
if (!buffer) return ''
const { detectEncoding = false, isHtml = false } = options
if (!detectEncoding) {
return String(buffer)
}
const fallbackEncoding = detectTextEncoding(buffer)
try {
// WHATWG decode handles BOM override and legacy encoding tables.
return whatwgEncoding.decode(buffer, fallbackEncoding)
} catch {
return String(buffer)
}
}
module.exports.decodeTextBuffer = decodeTextBuffer
/**
* Read contents of file
* @param {string} path
* @param {ReadTextFileOptions} [options]
* @returns {string}
*/
async function readTextFile(path, options = {}) {
async function readTextFile(path) {
try {
var data = await fs.readFile(path)
return decodeTextBuffer(data, options)
return String(data)
} catch (error) {
Logger.error(`[FileUtils] ReadTextFile error ${error}`)
return ''