300字范文,内容丰富有趣,生活中的好帮手!
300字范文 > JSZip解压 文件名乱码问题解决

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

时间:2021-06-29 12:32:06

相关推荐

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': ...});

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。