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

Can't handle error while readstream get error #20

Open
skyfore opened this issue Feb 9, 2018 · 1 comment
Open

Can't handle error while readstream get error #20

skyfore opened this issue Feb 9, 2018 · 1 comment

Comments

@skyfore
Copy link

skyfore commented Feb 9, 2018

'use strict';

const fs = require('fs');
const unZip = require('unzip2');

const fswrap = filepath => new Promise((resolve, reject) => {
  const readable = fs.createReadStream(filepath).pipe(unZip.Extract({ path: './' }));
  readable.on('close', () => resolve(buf));
  readable.on('error', err => reject(err));
});

const main = async () => {
  await fswrap('./notexistfile');
};

main().catch(e => console.error(e));

In this case, ./notexistfile is not exist, and I can't catch error. What should I do if I want to catch error.

@skyfore
Copy link
Author

skyfore commented Feb 9, 2018

I solve it with split code, such as

const fswrap = filepath => new Promise((resolve, reject) => {
  const readable = fs.createReadStream(filepath);
  const pipistream = readable.pip(unZip.Extract({ path: './' }));
  pipistream.on('close', () => resolve());
  readable.on('error', e => reject(e));
});

I do not know if it will parameter more problem, but I test can catch error or get right value.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant