提交 a3b8d04c authored 作者: macmini's avatar macmini

8

上级 39a01216
......@@ -65,3 +65,20 @@ if (execMatch) {
});
}
const { execSync } = require('child_process');
// 读取 .desktop 文件
const desktopFile1 = '/usr/share/applications/example.desktop';
const desktopContent = execSync(`cat ${desktopFile1}`).toString();
// 使用 file 命令获取文件类型和编码信息
const fileOutput = execSync(`file -i ${desktopFile1}`).toString();
const encodingMatch = fileOutput.match(/charset=(.*)/);
// 获取编码类型
const encoding = encodingMatch ? encodingMatch[1] : 'utf-8';
// 将 .desktop 文件内容从指定编码转换为 UTF-8
const desktopContentUtf8 = iconv.decode(Buffer.from(desktopContent), encoding).toString('utf-8');
Markdown 格式
0% 或
您添加了 0 人 到此讨论。请谨慎行事。
请先完成此评论的编辑!
请 注册 或者 后发表评论