Permalink
Browse files

[api test] Expose `BufferedStream.prototype.buffer` property

Export it which when set to `false` will disable all buffering.
USE WITH CAUTION. [ci skip]
  • Loading branch information...
1 parent ca48bde commit bc6076e1d1996b746e3c354f0b7ccde9d833a0e6 @indexzero indexzero committed with pksunkara Jan 23, 2012
Showing with 27 additions and 6 deletions.
  1. +18 −1 lib/buffered-stream.js
  2. +1 −1 test/fixtures/pipe-write-test.txt
  3. +8 −4 test/streaming-test.js
View
@@ -34,10 +34,24 @@ var BufferedStream = module.exports = function (limit) {
this.chunks = [];
this.writable = true;
this.readable = true;
+ this._buffer = true;
};
util.inherits(BufferedStream, stream.Stream);
+Object.defineProperty(BufferedStream.prototype, 'buffer', {
+ get: function () {
+ return this._buffer;
+ },
+ set: function (value) {
+ if (!value) {
+ delete this.chunks
+ }
+
+ this._buffer = value;
+ }
+});
+
BufferedStream.prototype.pipe = function () {
var self = this;
if (self.resume) {
@@ -91,7 +105,10 @@ BufferedStream.prototype.write = function (chunk) {
BufferedStream.prototype.end = function () {
this.readable = false;
this.ended = true;
- this.emit('end');
+
+ if (!this.chunks) {
+ this.emit('end');
+ }
};
BufferedStream.prototype.close = function () {
@@ -1 +1 @@
-hello world
+hello worldhello world
View
@@ -14,11 +14,15 @@ vows.describe('union/streaming').addBatch({
union.createServer({
before: [
function (req, res, next) {
+ var chunks = '';
+
+ req.buffer = false;
+ req.on('data', function (chunk) {
+ chunks += chunk;
+ });
+
req.on('end', function () {
- req.pipe(res);
- process.nextTick(function () {
- self.callback(null, chunks);
- })
+ self.callback(null, chunks);
});
}
]

0 comments on commit bc6076e

Please sign in to comment.