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 0000000..25a7188 Binary files /dev/null and "b/fixtures/\344\270\255\346\226\207\346\265\213\350\257\225.zip" differ diff --git a/index.js b/index.js index 3c1f943..01aacca 100644 --- a/index.js +++ b/index.js @@ -25,7 +25,7 @@ const extractEntry = (entry, zip) => { 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'); +});