node-lazy icon indicating copy to clipboard operation
node-lazy copied to clipboard

Problem with new streams API

Open glenjamin opened this issue 12 years ago • 6 comments
trafficstars

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

glenjamin avatar Mar 12 '13 00:03 glenjamin

Confirmed on OS X 10.8 too.

swestcott avatar Mar 12 '13 08:03 swestcott

Same issue on windows too.

davemkirk avatar Mar 15 '13 02:03 davemkirk

Ditto on Linux. Same (recursive) issue with stream.resume and other work around that I have been trying also.

NathanaelA avatar Mar 19 '13 17:03 NathanaelA

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.

NathanaelA avatar Mar 20 '13 04:03 NathanaelA

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.

mhart avatar Jun 28 '13 01:06 mhart

Forget my last comment, wrapping the stream using new Readable().wrap(stream) seems to make it all work.

mhart avatar Jun 28 '13 02:06 mhart