Skip to content

Instantly share code, notes, and snippets.

@efbeka
Created September 20, 2012 18:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save efbeka/3757644 to your computer and use it in GitHub Desktop.
Save efbeka/3757644 to your computer and use it in GitHub Desktop.
/*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");
@efbeka
Copy link
Author

efbeka commented Sep 20, 2012

If i pass { end: true } as options, the output is "2190 bytes written"

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