diff --git a/onlinefs/module/fsoperate.js b/onlinefs/module/fsoperate.js index 79aa56be..4aecee4a 100644 --- a/onlinefs/module/fsoperate.js +++ b/onlinefs/module/fsoperate.js @@ -6,6 +6,7 @@ const { } = require("./base_fsoperate"); const fsex = require('fs-extra'); const AdmZip = require('adm-zip'); +const iconv = require('iconv-lite'); @@ -150,6 +151,13 @@ class FileOperate extends BaseFileOperate { try { const zip = new AdmZip(absPath); const zipExtractDir = absPath.split('.')[0]; + // zip.extractAllTo(zipExtractDir, true); + // 解决目录中中文乱码问题 + const zipEntries = zip.getEntries(); + for (let i = 0; i < zipEntries.length; i++) { + const entry = zipEntries[i]; + entry.entryName = iconv.decode(entry.rawEntryName, 'gbk'); + } zip.extractAllTo(zipExtractDir, true); return true; } catch (err) { diff --git a/package-lock.json b/package-lock.json index 8afb8a2c..653551d3 100644 --- a/package-lock.json +++ b/package-lock.json @@ -13,6 +13,19 @@ "negotiator": "0.6.1" } }, + "adm-zip": { + "version": "0.4.13", + "resolved": "https://registry.npm.taobao.org/adm-zip/download/adm-zip-0.4.13.tgz", + "integrity": "sha1-WX4vjMNnIVHhMH0+lc3bx1ZyMUo=" + }, + "adm-zip-iconv": { + "version": "0.4.9", + "resolved": "https://registry.npm.taobao.org/adm-zip-iconv/download/adm-zip-iconv-0.4.9.tgz", + "integrity": "sha1-SUGLPuUrbJ4G+Vcg7zdYVv48qf8=", + "requires": { + "iconv-lite": "^0.4.18" + } + }, "array-flatten": { "version": "1.1.1", "resolved": "http://registry.npm.taobao.org/array-flatten/download/array-flatten-1.1.1.tgz", diff --git a/package.json b/package.json index 4e223178..091002cf 100644 --- a/package.json +++ b/package.json @@ -17,6 +17,8 @@ "paji" ], "dependencies": { + "adm-zip": "^0.4.13", + "adm-zip-iconv": "^0.4.9", "body-parser": "^1.17.2", "colors": "^1.1.2", "compression": "^1.7.2",