Permalink
Browse files

smarter handling of buffer streams

  • Loading branch information...
1 parent 0f79b4a commit 16326d2ee2e1a66b07e85a4aa2166e83c24ad5dc @maxogden committed Aug 3, 2012
Showing with 13 additions and 3 deletions.
  1. +3 −2 index.js
  2. +1 −1 package.json
  3. +9 −0 test.js
View
@@ -9,6 +9,8 @@ function ConcatStream(cb) {
this.on('error', cb)
}
+util.inherits(ConcatStream, stream.Stream)
+
ConcatStream.prototype.write = function(chunk) {
this.body.push(chunk)
}
@@ -24,15 +26,14 @@ ConcatStream.prototype.getBody = function () {
})
return first
}
+ if (this.body.length === 1) return this.body[0]
return this.body
}
ConcatStream.prototype.end = function() {
this.cb(false, this.getBody())
}
-util.inherits(ConcatStream, stream.Stream)
-
module.exports = function(cb) {
return new ConcatStream(cb)
}
View
@@ -1,7 +1,7 @@
{ "name" : "concat-stream"
, "description" : "writable stream that concatenates strings or data and calls a callback with the result"
, "tags" : ["stream", "simple", "util", "utility"]
-, "version" : "0.0.2"
+, "version" : "0.0.4"
, "author" : "Max Ogden <max@maxogden.com>"
, "repository" :
{ "type" : "git"
View
@@ -0,0 +1,9 @@
+var spawn = require('child_process').spawn
+var concat = require('./')
+
+var cmd = spawn('ls')
+cmd.stdout.pipe(
+ concat(function(err, out) {
+ console.log(err, out.toString())
+ })
+)

0 comments on commit 16326d2

Please sign in to comment.