Permalink
Browse files

join buffers correctly

  • Loading branch information...
1 parent 16326d2 commit 3b4a1f5426c5db138a588ae371bc66da17564851 @maxogden committed Aug 3, 2012
View
@@ -1,5 +1,6 @@
var stream = require('stream')
var util = require('util')
+var bufferjoiner = require('bufferjoiner')
function ConcatStream(cb) {
stream.Stream.call(this)
@@ -26,7 +27,13 @@ ConcatStream.prototype.getBody = function () {
})
return first
}
- if (this.body.length === 1) return this.body[0]
+ if (typeof(Buffer) !== "undefined" && Buffer.isBuffer(this.body[0])) {
+ var buffs = new BufferJoiner()
+ this.body.forEach(function(buf) {
+ buffs.add(buf)
+ })
+ return buffs.join()
+ }
return this.body
}

Some generated files are not rendered by default. Learn more.

Oops, something went wrong.

Some generated files are not rendered by default. Learn more.

Oops, something went wrong.

Some generated files are not rendered by default. Learn more.

Oops, something went wrong.

Some generated files are not rendered by default. Learn more.

Oops, something went wrong.

Some generated files are not rendered by default. Learn more.

Oops, something went wrong.

Some generated files are not rendered by default. Learn more.

Oops, something went wrong.

Some generated files are not rendered by default. Learn more.

Oops, something went wrong.
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.4"
+, "version" : "0.0.5"
, "author" : "Max Ogden <max@maxogden.com>"
, "repository" :
{ "type" : "git"
@@ -10,4 +10,7 @@
, "bugs" :
{ "url" : "http://github.com/maxogden/node-concat-stream/issues" }
, "engines" : ["node >= 0.4.0"]
+, "dependencies": {
+ "bufferjoiner": "0.1.3"
+ }
}
View
@@ -19,5 +19,13 @@ works with arrays too!
write.write([4,5,6])
write.end()
// data will be [1,2,3,4,5,6] in the above callback
+
+works with buffers too! can't believe the deals!
+
+ var write = concat(function(err, data) {})
+ write.write(new Buffer('hello '))
+ write.write(new Buffer('world'))
+ write.end()
+ // data will be a buffer that toString()s to 'hello world' in the above callback
MIT LICENSE

0 comments on commit 3b4a1f5

Please sign in to comment.