0

this is the code:

var stream = require('stream')
var ws = new stream.writable()
ws.write('hello')

but when run above code, it prompt

events.js:160
      throw er; // Unhandled 'error' event
      ^

Error: not implemented
    at Writable._write (_stream_writable.js:435:6)
    at doWrite (_stream_writable.js:307:12)
    at writeOrBuffer (_stream_writable.js:293:5)
    at Writable.write (_stream_writable.js:220:11)
    at Object.<anonymous> (/Users/suoyong/Desktop/test.js:15:4)
    at Module._compile (module.js:556:32)
    at Object.Module._extensions..js (module.js:565:10)
    at Module.load (module.js:473:32)
    at tryModuleLoad (module.js:432:12)
    at Function.Module._load (module.js:424:3)

what's wrong with this code, thanks advance!

1 Answer 1

3

You need to implement your own writable stream. Take a look at this post for how to create your own: How to implement a writable stream

From the article - you can try something like this:

var stream = require('stream');

var ws = new stream.Writable({
  write: function(chunk, encoding, next) {
    console.log(chunk.toString());
    next();
  }
});
ws.write('hello');
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.