Re: [nodejs] Re: help with streams

2014-02-14 Thread Denys Khanzhyiev
I have finally found what is wrong. Readable.push() may call _read again synchrnously so whole thing becomes recursive and buffers are swapped as I am adjusting position after call to push. 2014-02-12 18:50 GMT+02:00 Denys Khanzhyiev xden...@gmail.com: It looks like reading from growing file

Re: [nodejs] Re: help with streams

2014-02-12 Thread Denys Khanzhyiev
It looks like reading from growing file is not reliable at all . I have tested on real app again and reads from growing file return wrong chunks when close to current end of file. I even can not rely on fs.writableStream.bytesWritten value as it is always greater than reading stream position, and

[nodejs] Re: help with streams

2014-02-11 Thread Denys Khanzhyiev
Looks like it is not solved. Sometimes I get situation when fs.ReadStrem neither emit 'readable' nor 'end' when used on growing file in non flow mode. And I have no event to resume reading. Except maybe some timeout. 2014-02-08 19:53 GMT+02:00 Denys Khanzhyiev xden...@gmail.com: Solved by

[nodejs] Re: help with streams

2014-02-11 Thread Denys Khanzhyiev
Or maybe I understand it wrong. When I call fs.ReadStream.read should I expect it will emit 'end' during call? Ok it is better to look in sources. 2014-02-11 11:27 GMT+02:00 Denys Khanzhyiev xden...@gmail.com: Looks like it is not solved. Sometimes I get situation when fs.ReadStrem neither

[nodejs] Re: help with streams

2014-02-11 Thread Denys Khanzhyiev
This is not funny now. I am not able to make such simple thing. Now I am getting swapped chunks of data. https://gist.github.com/xdenser/8887437 when new read stream starts first 2 chunks of data are swapped. How is it possible? 2014-02-11 11:50 GMT+02:00 Denys Khanzhyiev xden...@gmail.com:

[nodejs] Re: help with streams

2014-02-11 Thread greelgorke
you can count bytes with by putting a passthrough stream in between var counter = new stream.Transform var count = 0 counter._transform = function(chunk, encoding, callback){ count += (chunk chunk.length) || 0 this.push(chunk) callback() }

[nodejs] Re: help with streams

2014-02-11 Thread greelgorke
In Addition to that, whenthe counter can emit something counter._transform = function(chunk, encoding, callback){ count += (chunk chunk.length) || 0 this.push(chunk) if(count = threshhold) this.emit('threshhold_reached') callback() } Am Dienstag, 11. Februar 2014 12:36:20 UTC+1 schrieb

Re: [nodejs] Re: help with streams

2014-02-11 Thread Denys Khanzhyiev
Ok I have created simple gist to test this. https://gist.github.com/xdenser/8944752 Just run file and you should see WTF! 49152 WTF! 114688 WTF! 180224 WTF! 245760 ... WTF! 4112384 writeStream finish WTF! 4177920 read Stream Finished if you see just writeStream finish read Stream Finished it

Re: [nodejs] Re: help with streams

2014-02-11 Thread Denys Khanzhyiev
same v0.10.15 Ubuntu 13.10 on ARMv9 2014-02-11 23:48 GMT+02:00 Denys Khanzhyiev xden...@gmail.com: Ok I have created simple gist to test this. https://gist.github.com/xdenser/8944752 Just run file and you should see WTF! 49152 WTF! 114688 WTF! 180224 WTF! 245760 ... WTF! 4112384

Re: [nodejs] Re: help with streams

2014-02-11 Thread Michael Hart
Your `writeChunk` call seems a bit fragile with the `setTimeout` there - I commented on the gist. I think a smaller test case might be easier to read/understand what you're trying to achieve. On Wednesday, 12 February 2014 08:48:48 UTC+11, Denys Khanzhiyev wrote: Ok I have created simple

Re: [nodejs] Re: help with streams

2014-02-11 Thread Denys Khanzhyiev
Thank you Michael, Yes return is missing before setTimeout. I have updated gist. But that does not change result. https://gist.github.com/xdenser/8944752 I think this is small enough. What I am trying to acheeve is to create CatchStream - a stream reading from growing file, where growing file is

[nodejs] Re: help with streams

2014-02-08 Thread Denys Khanzhyiev
Solved by creating actual stream implementing _read. The trick is to call push on each _read. When there is no data, delay pull until data available. In my stream `_read` i call `read` of fs.ReadStream. As I understand I should either rely on `fs.ReadStream.read` and 'end' event. Or 'data' and