Tj Holowaychuk
14 years ago
3 changed files with 35 additions and 44 deletions
@ -0,0 +1,22 @@ |
|||
|
|||
/*! |
|||
* Canvas - Buffer |
|||
* Copyright (c) 2010 LearnBoost <tj@learnboost.com> |
|||
* MIT Licensed |
|||
*/ |
|||
|
|||
/** |
|||
* Concatenate `this` Buffer with `other`. |
|||
* |
|||
* @param {Buffer} other |
|||
* @return {Buffer} |
|||
* @api public |
|||
*/ |
|||
|
|||
Buffer.prototype.concat = function(other) { |
|||
var len = this.length |
|||
, buf = new Buffer(len + other.length); |
|||
this.copy(buf, 0, 0); |
|||
other.copy(buf, len, 0); |
|||
return buf; |
|||
}; |
@ -1,36 +0,0 @@ |
|||
|
|||
/*! |
|||
* Canvas - utils |
|||
* Copyright (c) 2010 LearnBoost <tj@learnboost.com> |
|||
* MIT Licensed |
|||
*/ |
|||
|
|||
/** |
|||
* Concatenate `bufs` / `lens`. |
|||
* |
|||
* @param {Array} bufs |
|||
* @param {Array} lens |
|||
* @return {Buffer} |
|||
* @api private |
|||
*/ |
|||
|
|||
exports.concatBuffers = function(bufs, lens) { |
|||
var buf |
|||
, length = 0 |
|||
, offset = 0; |
|||
|
|||
// Determine length
|
|||
for (var i = 0, len = lens.length; i < len; ++i) { |
|||
length += lens[i]; |
|||
} |
|||
|
|||
// Allocate buffer
|
|||
buf = new Buffer(length); |
|||
|
|||
// Copy
|
|||
for (var i = 0, len = bufs.length; i < len; ++i) { |
|||
bufs[i].copy(buf, offset); |
|||
offset += lens[i]; |
|||
} |
|||
return buf; |
|||
}; |
Loading…
Reference in new issue