max-mapper / extract-zip

Zip extraction written in pure JavaScript. Extracts a zip into a directory.
BSD 2-Clause "Simplified" License
388 stars 126 forks source link

如何解决中文名称的乱码问题 #109

Open luuman opened 3 years ago

longnhp-agiletechvn commented 3 years ago

The only solution: use English, that's all! Using Chinese in the wrong place will make you lower yourself.

ShinChven commented 3 years ago

const compressing = require('compressing');

const result = await compressing.zip.uncompress(file, unpackDir, { zipFileNameEncoding: 'GBK' });

KevinAo22 commented 3 years ago

The only solution: use English, that's all! Using Chinese in the wrong place will make you lower yourself.

Where is the correct place for using Chinese?

KevinAo22 commented 3 years ago

use JSZip to load data and write data into file system.

longnhp-agiletechvn commented 3 years ago

The only solution: use English, that's all! Using Chinese in the wrong place will make you lower yourself.

Where is the correct place for using Chinese?

LOL so why don't you answer him in Chinese but in English? Don't you find yourself ridiculous? My answer was in your comment.

KevinAo22 commented 3 years ago

The only solution: use English, that's all! Using Chinese in the wrong place will make you lower yourself.

Where is the correct place for using Chinese?

LOL so why don't you answer him in Chinese but in English? Don't you find yourself ridiculous? My answer was in your comment.

I'm worried about your brain cannot handle Chinese. Pity you and help you understand.

longnhp-agiletechvn commented 3 years ago

The only solution: use English, that's all! Using Chinese in the wrong place will make you lower yourself.

Where is the correct place for using Chinese?

LOL so why don't you answer him in Chinese but in English? Don't you find yourself ridiculous? My answer was in your comment.

I'm worried about your brain cannot handle Chinese. Pity you and help you understand.

Be superior in your own Chinese home, please! Nobody cares about your language, so you don't have to show others that you're a clown. Why do I need to handle Chinese? To be a clown like you? LMAO

liujiusheng commented 2 years ago

抄个代码还受到了歧视,我也换一个好啦

hellobugme commented 2 years ago

抄个代码还受到了歧视,我也换一个好啦

它又不是开发者,就一没脑子的傻卵罢了

kirrs commented 2 years ago

yauzl use cp437 encoding, you can find it here https://github.com/thejoshwolfe/yauzl/blob/master/index.js#L757

so you can do something like below

const extract = require("extract-zip");
const iconv = require('iconv-lite')

const cp437 = '\u0000☺☻♥♦♣♠•◘○◙♂♀♪♫☼►◄↕‼¶§▬↨↑↓→←∟↔▲▼ !"#$%&\'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~⌂ÇüéâäàåçêëèïîìÄÅÉæÆôöòûùÿÖÜ¢£¥₧ƒáíóúñѪº¿⌐¬½¼¡«»░▒▓│┤╡╢╖╕╣║╗╝╜╛┐└┴┬├─┼╞╟╚╔╩╦╠═╬╧╨╤╥╙╘╒╓╫╪┘┌█▄▌▐▀αßΓπΣσµτΦΘΩδ∞φε∩≡±≥≤⌠⌡÷≈°∙·√ⁿ²■ '

function decodeCp437(str) {
  const buffArr = []
  for (const s of str) {
    buffArr.push(cp437.indexOf(s))
  }
  return Buffer.from(buffArr)
}

extract(
  'special encoding file name.zip',
  {
    dir: 'your unzip dir',
    onEntry: function (entry) {
     // decode
      entry.fileName = iconv.decode(decodeCp437(entry.fileName), 'special encoding')
    }
  }
)
  .then(() => { })

the solution is not so good because it did something opposite to yauzl But you can use it as a temporary solution before extract-zip supports decodeStrings

doornot commented 2 years ago

what "special encoding" should i set, tried 'GBK' is not working. @KirrsGool

chirsz-ever commented 2 years ago

ZIP format do not contain the encoding information of the file names, you need determine it by yourself or detect it (for Simplified Chinese it may be GBK).


ZIP 格式没有包含文件名的编码信息, 你需要自行决定或者探测解压时使用的编码, 简体中文一般是 GBK.