[nodejs] How to read some bytes from a file readable stream and then close the stream under certain condition?

2013-07-11 Thread Benjamin Pasero
Hi, I am wondering whats the best way of reading some data from a file stream (readable stream) and under a certain condition stop reading? Is it safe to e.g. call destroy() from within the on('data') handler? Or do I even have to cleanup the stream at all? Take this example in pseudo code: v

Re: [nodejs] How to read some bytes from a file readable stream and then close the stream under certain condition?

2013-07-12 Thread Ben Noordhuis
On Thu, Jul 11, 2013 at 5:52 PM, Benjamin Pasero wrote: > Hi, > > I am wondering whats the best way of reading some data from a file stream > (readable stream) and under a certain condition stop reading? Is it safe to > e.g. call destroy() from within the on('data') handler? Or do I even have to >

Re: [nodejs] How to read some bytes from a file readable stream and then close the stream under certain condition?

2013-07-13 Thread Benjamin Pasero
So you say, destroying a stream like that should not trigger any error? -- -- Job Board: http://jobs.nodejs.org/ Posting guidelines: https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines You received this message because you are subscribed to the Google Groups "nodejs" group. To p

Re: [nodejs] How to read some bytes from a file readable stream and then close the stream under certain condition?

2013-07-13 Thread Ben Noordhuis
On Sat, Jul 13, 2013 at 10:37 AM, Benjamin Pasero wrote: > So you say, destroying a stream like that should not trigger any error? No. -- -- Job Board: http://jobs.nodejs.org/ Posting guidelines: https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines You received this message bec

Re: [nodejs] How to read some bytes from a file readable stream and then close the stream under certain condition?

2013-07-13 Thread Benjamin Pasero
so I read into the source code of readable stream in fs and I can see that destroy() calls close() in the end but it does not support any callback. it seems to me that calling close() on the stream and passing in a callback is much safer because I can continue when the stream is really closed. s