kevva / download

Download and extract files
MIT License
1.28k stars 200 forks source link

plugin errors are ignored #84

Closed piranna closed 8 years ago

piranna commented 9 years ago

The call to ware at https://github.com/kevva/download/blob/bac7dd9913302c37564b087f9e198658f5692234/index.js#L125-L129 doesn't a callback, so any error produced when registering the plugins are ignored. The same happen with the errors generated by them, since the stream is downloaded and decompressed in a different path two lines below. I think the call to readAllStream() should be done inside that callback I say inside the 'response' event. Maybe there would be problems due to issue #83, but I think both can be fixed at the same time.

flippidippi commented 8 years ago

Bump, I would like to use .use to check headers before continuing the download process but throwing an error doesn't cleanly exit.

kevva commented 8 years ago

Plugins are now removed. I'm returning the full stream so that you can do whatever you want with it.

piranna commented 8 years ago

Have you removed the .use() function? How are they used now, with .pipe()?

kevva commented 8 years ago

download returns a stream (and a promise), so you can just listen on the response event.

const dl = download('cat.com/dancing.gif');

dl.on('response', res => {
    res.on('data', yourFunction);
};

dl.then(() => console.log('done!'));
piranna commented 8 years ago

:+1: