node-lazy
node-lazy copied to clipboard
Problem with new streams API
I can't quite figure out what's causing this, but I've got a reproducible testcase (on my OS X machine, anyway).
Sample file:
var lazy = require("lazy"),
fs = require("fs");
fs.writeFileSync('./data.txt', "1\n2\n3", "utf8")
var stream = fs.createReadStream('./data.txt');
new lazy(stream)
.lines
.forEach(function(line) {
console.log(line.toString());
});
On 0.8
> n use 0.8.* temp.js
1
2
3
On 0.10
> n use 0.10.* temp.js
I tried calling stream.resume() to force it into old stream mode, but this kicked it into an infinite loop (stack limit reached) outputting the first item repeatedly.
Discovered by @swestcott
Confirmed on OS X 10.8 too.
Same issue on windows too.
Ditto on Linux. Same (recursive) issue with stream.resume and other work around that I have been trying also.
Fix should be in: https://github.com/pkrumins/node-lazy/pull/33 --- thanks for the test case; that narrowed down why the other module was breaking. The issue wasn't the new streams interface, it was that Node 10 also made some changes to the EventEmitter. After tracing down that the EE was acting really wonky I went and found a commit in the Node code base (https://github.com/joyent/node/issues/4971) that described what they changed and how the EE had to be created. However, then several things had to be changed to make it work.
I'm still seeing this behaviour with the latest version (1.0.11) on node v0.10.11 - with at least one module anyway (https://github.com/rvagg/node-levelup). ie - there's no output.
It works fine with lazy in v0.8.x
If I comment out the // Check for v0.10 block in lazy.js, everything works fine.
Forget my last comment, wrapping the stream using new Readable().wrap(stream) seems to make it all work.