1

I'm using the archiver package in order to compress files and upload them via a stream.

It's my first time using streams in Node.js, and in the documentation of archiver I have stumbled upon the following case:

// good practice to catch this error explicitly
archive.on('error', function(err) {
  throw err;
});

In this scenario, is it necessary to listen on error just to throw it? Does it make any difference if I simply omit this step?

If not, why is it considered a good practice by the docs?

pakut2
  • 500
  • 5
  • 21
  • not a bad question, but have you tried omitting it and seeing for yourself if there's a difference? – Sasha Kondrashov Mar 27 '23 at 10:46
  • 1
    I did and it doesn't seem to make any noticeable difference. The same error is thrown, but I am wondering if it has some other implications, e.g. whether the stream is closed correctly without the `error` listener etc. – pakut2 Mar 27 '23 at 10:50

0 Answers0