先使用jschardet检测出文件编码,然后用iconv解码
export const f_decodeFile = (fp:string):string =>{
if(!fs.existsSync(fp)){
throw new Error(`文件${fp}不存在`);
}
const buf = fs.readFileSync(fp)
const result = jschardet.detect(buf)
const res = iconv.decode(buf, result.encoding) //使用iconv转成中文格式
return res;
}