Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

.lines skips last unterminated line #43

Open
sehrgut opened this issue Aug 23, 2013 · 1 comment
Open

.lines skips last unterminated line #43

sehrgut opened this issue Aug 23, 2013 · 1 comment

Comments

@sehrgut
Copy link

sehrgut commented Aug 23, 2013

var Lazy = require('lazy');
var l = Lazy();
l.lines.join(function (x) { console.log(x); });
l.emit('data', 'abc\ndef');
l.emit('end');

Expected output:

[ <Buffer 61 62 63>, <Buffer 64 65 66> ]

Actual output:

[ <Buffer 61 62 63> ]
@sehrgut
Copy link
Author

sehrgut commented Aug 23, 2013

This appears to have something to do with the relationship between how join is triggered, and how lines emits its final buffer. Here's a bit of sample code, and its output:

var Lazy = require('./lazy');
var l = new Lazy();
l.lines.join(function (x) { console.log(x); });
l.emit('data', 'abcdef');
l.emit('end');

I put logging lines at various points, which you'll see.

pushing last line
bucket emitting pipe event
join received pipe event
[]
bucket yielding final buffer on end event: "abcdef"

Those logging lines are:

  1. lines pushing the last bit of data
  2. bucket receiving and delegating the "pipe" event to its internal Lazy
  3. join receiving the "pipe" event from bucket and calling its callback
  4. My callback, printing an empty array.
  5. bucket getting the "end" event and yielding the final buffer, too late for join, and the contents of that buffer.

I hope this is helpful in resolving the issue. I wasn't able to figure out a satisfactory solution myself.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant