Skip to content

Instantly share code, notes, and snippets.

@isaacs isaacs/z.js
Created Dec 15, 2012

What would you like to do?
var Writable = require('stream').Writable;
var util = require('util');
// a lowlevel stderr writer
var TTY = process.binding('tty_wrap').TTY;
var handle = new TTY(2, false);
util.inherits(W, Writable);
function W(opts) {, opts);
W.prototype._write = function(chunk, cb) {
var str = util.format('chunk %j', chunk.toString()) + '\n';
var req = handle.writeUtf8String(str);
// here's the problem.
// it needs to tell the Writable machinery that it's ok to write
// more, but that the current buffer length is handle.writeQueueSize
req.oncomplete = afterWrite
req.cb = cb;
console.error('before write', handle.writeQueueSize);
function afterWrite(status, handle, req) {
console.error('afterWrite', status, handle.writeQueueSize);
var w = new W
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.