Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support options from outside for fix chinese filename. #19

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
node_modules
.idea/
package-lock.json
Binary file added fixtures/中文测试.zip
Binary file not shown.
6 changes: 3 additions & 3 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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}`));
}
Expand All @@ -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);
};
10 changes: 9 additions & 1 deletion test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down Expand Up @@ -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');
});