node-modules / compressing

Everything you need for compressing and uncompressing
MIT License
431 stars 36 forks source link

解压中文文件名的时候,出现乱码 #23

Closed minikiller closed 1 year ago

minikiller commented 5 years ago

代码如下:

compress() {
                const compressing = require('compressing');
                // 解压缩
                compressing.zip.uncompress('build.zip', 'nodejs-compressing-demo3')
                    .then(() => {
                        console.log('success');
                    })
                    .catch(err => {
                        console.error(err);
                    });
            },

测试zip文件中包含有中文文件名的文件时候,解压出来的文件名是乱码。

HiKWang commented 5 years ago

同问

justquanyin commented 5 years ago

+1

fengmk2 commented 5 years ago

如果你压缩之前的文件名不是 utf8 的,那么解压出来就会乱码。估计还得增加一个编码参数才行。

helloyoucan commented 4 years ago

+1

zhipenglin commented 4 years ago

加个参数大概就好了,可以试试。找了一上午,看了源码才发现,这个包是支持传字符集参数的

compress() {
                const compressing = require('compressing');
                // 解压缩
                compressing.zip.uncompress('build.zip', 'nodejs-compressing-demo3',{
zipFileNameEncoding:'GBK'
})
                    .then(() => {
                        console.log('success');
                    })
                    .catch(err => {
                        console.error(err);
                    });
            },
InCodingNowLiu commented 3 years ago

线上打包出来,这个字符集参数不起作用,本地dev启动是好的,线上走prod的webpack打包出来是有问题的,有遇到这种情况的小伙伴么

mxlt02 commented 1 year ago

加个参数大概就好了,可以试试。找了一上午,看了源码才发现,这个包是支持传字符集参数的

compress() {
                const compressing = require('compressing');
                // 解压缩
                compressing.zip.uncompress('build.zip', 'nodejs-compressing-demo3',{
zipFileNameEncoding:'GBK'
})
                    .then(() => {
                        console.log('success');
                    })
                    .catch(err => {
                        console.error(err);
                    });
            },

有效!

fengmk2 commented 1 year ago

不知道 zip 的 entry 是否有字符编码信息,如果有就可以自动探测编码解决 https://github.com/node-modules/compressing/blob/ff9178c51ff0f2e75ac0b31cc661cf43bc657035/lib/zip/uncompress_stream.js#L88

fengmk2 commented 1 year ago

有人可以提供一个有问题的 zip 测试文件么,这样我可以作为测试用例,尝试解决一下。

mxlt02 commented 1 year ago

有人可以提供一个有问题的 zip 测试文件么,这样我可以作为测试用例,尝试解决一下。

configs.zip image

fengmk2 commented 1 year ago

有人可以提供一个有问题的 zip 测试文件么,这样我可以作为测试用例,尝试解决一下。

configs.zip image

Thanks♪(・ω・)ノ

fengmk2 commented 1 year ago

entry 缺少文件名字符编码的信息,无法做到完全自动化解决。只能由用户传入指定文件编码参数了。

Entry {
  versionMadeBy: 20,
  versionNeededToExtract: 20,
  generalPurposeBitFlag: 6,
  compressionMethod: 8,
  lastModFileTime: 30788,
  lastModFileDate: 22292,
  crc32: 2382850333,
  compressedSize: 54890,
  uncompressedSize: 529664,
  fileNameLength: 103,
  extraFieldLength: 188,
  fileCommentLength: 0,
  internalFileAttributes: 0,
  externalFileAttributes: 32,
  relativeOffsetOfLocalHeader: 0,
  fileName: <Buffer 43 52 31 37 66 69 78 5f b7 c0 c9 c1 cd cb bb fa d0 cd cd a8 d3 c3 33 5f 62 79 63 68 65 6e a3 a8 b4 f2 bf aa 41 50 50 c9 c1 cd cb bf c9 d2 d4 b3 a4 b0 ... 53 more bytes>,
  extraFields: [
    {
      id: 10,
      data: <Buffer 00 00 00 00 01 00 18 00 08 d1 1a 3b 34 d3 d9 01 c5 64 4d d7 35 d3 d9 01 59 a1 ed 74 34 d3 d9 01>
    },
    {
      id: 28789,
      data: <Buffer 01 e6 f9 f8 c5 43 52 31 37 66 69 78 5f e9 98 b2 e9 97 aa e9 80 80 e6 9c ba e5 9e 8b e9 80 9a e7 94 a8 33 5f 62 79 63 68 65 6e ef bc 88 e6 89 93 e5 bc ... 98 more bytes>
    }
  ],
  fileComment: <Buffer >,
  comment: <Buffer >
}