特性:
1、支持任意深度的chm文件解析
2、解析后内容结构转换为tree数据呈现
3、点击树节点可以在html实时查看数据
4、不依赖任何浏览器端插件,兼容性较好
nodejs端核心代码
const $g = global.SG.$g, fs = global.SG.fs, router = global.SG.router, xlsx = global.SG.xlsx;
module.exports = global.SG.router;
let webRootPath = 'http://127.0.0.1:9999/chm/';//测试环境chm文件根目录
//上传单个文件(all方法支持POST、GET、PUT、PATCH、DELETE传参方式)
let uploadFileName = '';//获取上传后的文件名
router.all(
"/chm/upload",//接口路径
$g.dir.upload(
"./upload",//存储临时上传文件的路径
({ fileName, } = {}) => { uploadFileName = fileName; }).single("file"),//上传单个文件
(req, res) => {
// 开始解压上传的upload文件----------------------------------------
let cp = require('child_process');
cp.exec("reg query HKEY_CLASSES_ROOT\\360zip\\shell\\open\\command /ve", function (e, stdout, stderr) {
let rootPath = `${__dirname.split('\\').slice(0, -3).join('\\')}`;
let uploadFolderPath = `${rootPath}\\upload\\${uploadFileName}`;
let targetFolderPath = `${rootPath}\\chm\\${uploadFileName}`;
let str = stdout.match(/\"([^\"]+)\"/)[0];
if (str) {
// console.log('已经找到360zip程序,详细地址为:'+str);
cp.exec(`${str} -x ${uploadFolderPath} ${targetFolderPath}`, { encoding: 'binary' }, function (e, stdout, stderr) {
// 遍历读取目录里面的文件----------------------------------------
let files = [];
let walker = require('walk').walk(targetFolderPath, { followLinks: false });
walker.on('file', function (roots, stat, next) {
if (stat.name.includes(&#