Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Support node v0.6 by adding in Buffer.concat

  • Loading branch information...
commit 8f968c46d75a28ac1cbd575634d799183ecc790b 1 parent 2514cd6
@baudehlo authored
Showing with 31 additions and 0 deletions.
  1. +31 −0 chunkemitter.js
View
31 chunkemitter.js
@@ -12,6 +12,37 @@ function ChunkEmitter(buffer_size) {
util.inherits(ChunkEmitter, EventEmitter);
+if (!Buffer.concat) {
+ Buffer.concat = function(list, length) {
+ if (!Array.isArray(list)) {
+ throw new Error('Usage: Buffer.concat(list, [length])');
+ }
+
+ if (list.length === 0) {
+ return new Buffer(0);
+ } else if (list.length === 1) {
+ return list[0];
+ }
+
+ if (typeof length !== 'number') {
+ length = 0;
+ for (var i = 0; i < list.length; i++) {
+ var buf = list[i];
+ length += buf.length;
+ }
+ }
+
+ var buffer = new Buffer(length);
+ var pos = 0;
+ for (var i = 0; i < list.length; i++) {
+ var buf = list[i];
+ buf.copy(buffer, pos);
+ pos += buf.length;
+ }
+ return buffer;
+ };
+}
+
ChunkEmitter.prototype.fill = function (input) {
if (typeof input === 'string') {
input = new Buffer(input);
Please sign in to comment.
Something went wrong with that request. Please try again.