Created
September 20, 2012 18:49
-
-
Save efbeka/3757644 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/*jshint node:true strict:true laxcomma:true es5:true*/ | |
"use strict"; | |
var http = require('http') | |
, Stream = require('stream') | |
, fs = require('fs') | |
, path = require('path') | |
, server | |
; | |
var s = new Stream() | |
, bytes = 0 | |
; | |
s.writable = true; | |
s.write = function (buf) { | |
bytes += buf.length; | |
}; | |
s.end = function (buf) { | |
if (arguments.length) { | |
s.write(buf); | |
} | |
s.writable = false; | |
console.log(bytes + ' bytes written'); | |
}; | |
s.destroy = function() { | |
s.writable = false; | |
}; | |
fs.createReadStream('/etc/passwd').pipe(s, { end: false }); | |
s.end("ii"); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
If i pass { end: true } as options, the output is "2190 bytes written"