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': ...
});
标签:解压,...,iconv,zip,function,JSZip,乱码,file,bin 来源: https://blog.csdn.net/qq_40036799/article/details/117280941