JSZip解压,文件名乱码问题解决

官方文档解释
需要额外安装

npm i iconv-lite -S

官方演示代码:(其中cp866改为gbk可解决中文乱码)

// here, "bin" is a russian zip file, using the cp866 encoding for file names
// by default, using UTF-8 leads to wrong file names:
zip.loadAsync(bin)
.then(function (zip) {
    console.log(zip.files);
    // '����� �����/': ...
    // '����� �����/����� ⥪�⮢�� ���㬥��.txt': ...
});

// using the correct encoding solve the issue:
var iconv = require('iconv-lite');
zip.loadAsync(bin, {
  decodeFileName: function (bytes) {
    return iconv.decode(bytes, 'cp866');
  }
})
.then(function (zip) {
    console.log(zip.files);
    // 'Новая папка/': ...
    // 'Новая папка/Новый текстовый документ.txt': ...
});
上一篇:php原生导出csv文件


下一篇:Android TabHost中Activity之间传递数据