From f451c580c7c1617b6dbc1c5f1d1de98e85595692 Mon Sep 17 00:00:00 2001 From: imcuttle Date: Mon, 7 May 2018 13:52:42 +0800 Subject: [PATCH] Support options from outside for fix chinese filename --- .gitignore | 2 ++ ...0\255\346\226\207\346\265\213\350\257\225.zip" | Bin 0 -> 800 bytes index.js | 6 +++--- test.js | 10 +++++++++- 4 files changed, 14 insertions(+), 4 deletions(-) create mode 100755 "fixtures/\344\270\255\346\226\207\346\265\213\350\257\225.zip" diff --git a/.gitignore b/.gitignore index 3c3629e..b918765 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,3 @@ node_modules +.idea/ +package-lock.json diff --git "a/fixtures/\344\270\255\346\226\207\346\265\213\350\257\225.zip" "b/fixtures/\344\270\255\346\226\207\346\265\213\350\257\225.zip" new file mode 100755 index 0000000000000000000000000000000000000000..25a7188bab32d3809980a9718caf548685637c96 GIT binary patch literal 800 zcmWIWW@Zs#-~d9enpxfqNPwR~fZ@rGwa=!tKik^+EC$Hnz*&YI`5*FD`k_4$+)Pj>Y^T|491lzmTjG(6cg`{mqu z&*rr}-M#Ditd{4UJD;uV0y3U<_C8;|{>9doXS*f@c(Zd{dhE9rDZ1bzgMf-poAJtf6e}s#&It|GN^b=Kd+O7nhzIA1$``{(j~;X}s=R zaC8kS$@9+-rT3yq5MK-UiiStZYP=HNmQ=yRJJo|U@ao_eto!`FsXtn9_mWpZb zgN|!mN_=(S?5z9QxNx(bnxYD?J8F!0&h0hWWiZ!5!RyhDFLM-3-WqIKbMQc^jCET+ zC`JytoYP=tWMC));s9?(CQ)WY;3CHsKLZaeiX4_Sf|wZL%K=Y05QA_ { const file = { mode: (entry.externalFileAttributes >> 16) & 0xFFFF, mtime: entry.getLastModDate(), - path: entry.fileName + path: entry.fileName.toString() }; file.type = getType(entry, file.mode); @@ -73,7 +73,7 @@ const extractFile = zip => new Promise((resolve, reject) => { zip.on('end', () => resolve(files)); }); -module.exports = () => buf => { +module.exports = opt => buf => { if (!Buffer.isBuffer(buf)) { return Promise.reject(new TypeError(`Expected a Buffer, got ${typeof buf}`)); } @@ -82,5 +82,5 @@ module.exports = () => buf => { return Promise.resolve([]); } - return pify(yauzl.fromBuffer)(buf, {lazyEntries: true}).then(extractFile); + return pify(yauzl.fromBuffer)(buf, Object.assign({lazyEntries: true}, opt)).then(extractFile); }; diff --git a/test.js b/test.js index bfeb0be..a1756c4 100644 --- a/test.js +++ b/test.js @@ -3,7 +3,7 @@ import path from 'path'; import isJpg from 'is-jpg'; import pify from 'pify'; import test from 'ava'; -import m from './'; +import m from '.'; const fsP = pify(fs); @@ -46,3 +46,11 @@ test('return empty array if non-valid file is supplied', async t => { test('throw on wrong input', async t => { await t.throws(m()('foo'), 'Expected a Buffer, got string'); }); + +test('chinese zipfile', async t => { + const buf = await fsP.readFile(path.join(__dirname, 'fixtures', '中文测试.zip')); + const files = await m({decodeStrings: false})(buf); + + t.is(files[0].path, '中文测试.md'); + t.is(files[0].type, 'file'); +});