Skip to content

Instantly share code, notes, and snippets.

@garthk
Created February 28, 2014 04:04
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save garthk/9265037 to your computer and use it in GitHub Desktop.
Save garthk/9265037 to your computer and use it in GitHub Desktop.
var stream = require('stream');
function streamify(text) {
var s = new stream.Readable();
s.push(text);
s.push(null);
return s;
}
streamify('foo\n').pipe(process.stdout);
@garthk
Copy link
Author

garthk commented Feb 28, 2014

Usage: node _readnoop

Expected result: the same crash as if you'd done this in the REPL:

$ node
var s = new stream.Readable();
undefined
s.push('foo')
true

events.js:72
        throw er; // Unhandled 'error' event
              ^
Error: not implemented
    at Readable._read (_stream_readable.js:446:22)
    at Readable.read (_stream_readable.js:320:10)
    at maybeReadMore_ (_stream_readable.js:431:12)
    at _stream_readable.js:422:7
    at process._tickCallback (node.js:415:13)

Actual result in Node v0.10.26:

$ node _readnoop.js 
foo

@changjie-lin
Copy link

Thank you for posting this answer on stackoverflow.

@shinout
Copy link

shinout commented Feb 25, 2016

+1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment