decompress icon indicating copy to clipboard operation
decompress copied to clipboard

Unsupport Chinese Character

Open Comee opened this issue 8 years ago • 8 comments

The zip file structure is:

image

After decompress, the structure is:

image

Note: file name is not correct.

Comee avatar Dec 14 '16 03:12 Comee

Can you submit a failing test?

sindresorhus avatar Apr 24 '17 10:04 sindresorhus

@Comee How to resolve it finally ?

yozosann avatar Sep 19 '18 07:09 yozosann

You can fix it before you write it to disk

index.js

image

Comee avatar Sep 19 '18 08:09 Comee

You can fix it before you write it to disk

index.js

image

好像不行,我到yauzl里去处理了才行- -

yozosann avatar Sep 19 '18 08:09 yozosann

I write a function to convert garble path to chinese. You can try it in your needed place.

decompress(path.join(__dirname, './七夕的副本.zip'), './中奖名单').then(files => {
    files.forEach(file => console.log(garbleToChinese(file.path)));
});

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

get result:

七夕的副本/
七夕的副本/.DS_Store
__MACOSX/
__MACOSX/七夕的副本/
__MACOSX/七夕的副本/._.DS_Store
七夕的副本/1.png
__MACOSX/七夕的副本/._1.png
七夕的副本/收集卡 /
七夕的副本/收集卡 /.DS_Store

yozosann avatar Sep 19 '18 09:09 yozosann

@yozosann you saved my day

wizardpisces avatar Dec 19 '18 07:12 wizardpisces

@yozosann In this way, only the correct characters can be output on the console. In fact, the extracted file name on the server is still garbled

hopepdm avatar Jun 29 '20 02:06 hopepdm

import iconvLite from 'iconv-lite';

decompress(foo, {
  map(file) {
    return {
      ...file,
      path: iconvLite.encode(file.path, 'cp437').toString(),
    };
  },
})

meteorlxy avatar Mar 02 '23 12:03 meteorlxy