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

GZIP + Error: ENOENT: no such file or directory #15

Open
belaa007 opened this issue Oct 18, 2018 · 0 comments
Open

GZIP + Error: ENOENT: no such file or directory #15

belaa007 opened this issue Oct 18, 2018 · 0 comments

Comments

@belaa007
Copy link

belaa007 commented Oct 18, 2018

If you use gzip: true, and the file doesn't exist, the module throws an unhandles exception:
{ Error: ENOENT: no such file or directory, open 'asd' errno: -2, code: 'ENOENT', syscall: 'open', path: 'asd' }

The issue is in the big-xml.js file, starting line 20:

  if (options.gzip) {
    var gunzip = zlib.createGunzip();
    stream.pipe(gunzip);
    stream = gunzip;
  }

After this, in line 34, there is indeed an intended error handling:

  stream.on('error', function(err) {
    self.emit('error', new Error(err));
  });

But since here the stream variable is not
var stream = fs.createReadStream(filename);
anymore, it cannot catch errors from from the original stream variable.

My idea to fix this would be to raise the stream.on before the if block, and add a plus error listener in the if block :

  stream.on('error', function(err) {
    self.emit('error', new Error(err));
  });
    
  if (options.gzip) {
    var gunzip = zlib.createGunzip();
    gunzip.on('error', function(err) {
      self.emit('error', new Error(err));
    });
    stream.pipe(gunzip);
    stream = gunzip;
  }
belaa007 added a commit to belaa007/node-big-xml that referenced this issue Oct 18, 2018
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