index.js
function pack(buffs, extra) {
  var lengths = [],
      lenbytes = [],
      len = buffs.length,
      extra = extra || 0,
      sum = 0,
      offset = 0,
      mb,
      i

  for (i = 0; i < len; i++) {
    lengths.push(buffs[i].length)
    lenbytes.push(vencode(lengths[i]))
    sum += lengths[i] + lenbytes[i].length + extra
  }

  mb = new Buffer(sum)
  for (i = 0; i < len; i++) {
    for (var j = 0; j < lenbytes[i].length; j++) {
      mb.writeUInt8(lenbytes[i][j], offset + extra)
      offset = offset + 1 + extra
    }
    buffs[i].copy(mb, offset, 0, lengths[i])
    offset += lengths[i]
  }
  return mb
}
function pack(buffs, extra) {
  var lengths = [],
      lenbytes = [],
      len = buffs.length,
      extra = extra || 0,
      sum = 0,
      offset = 0,
      mb,
      i

  for (i = 0; i < len; i++) {
    lengths.push(buffs[i].length)
    lenbytes.push(vencode(lengths[i]))
    sum += lengths[i] + lenbytes[i].length + extra
  }

  mb = new Buffer(sum)
  for (i = 0; i < len; i++) {
    for (var j = 0; j < lenbytes[i].length; j++) {
      mb.writeUInt8(lenbytes[i][j], offset + extra)
      offset = offset + 1 + extra
    }
    buffs[i].copy(mb, offset, 0, lengths[i])
    offset += lengths[i]
  }
  return mb
}
function pack ( buffs , extra ) { var lengths = [ ] , lenbytes = [ ] , len = buffs . length , extra = extra || 0 , sum = 0 , offset = 0 , mb , i for ( i = 0 ; i < len ; i ++ ) { lengths . push ( buffs [ i ] . length ) lenbytes . push ( vencode ( lengths [ i ] ) ) sum += lengths [ i ] + lenbytes [ i ] . length + extra } mb = new Buffer ( sum ) for ( i = 0 ; i < len ; i ++ ) { for ( var j = 0 ; j < lenbytes [ i ] . length ; j ++ ) { mb . writeUInt8 ( lenbytes [ i ] [ j ] , offset + extra ) offset = offset + 1 + extra } buffs [ i ] . copy ( mb , offset , 0 , lengths [ i ] ) offset += lengths [ i ] } return mb }
Combine an array of buffers into a single buffer encoded such that they can all be extracted again.
@param  {Array[Buffer]} buffs An array of Buffers
@param  {int} extra How many extra empty leading bytes to put in each buffer
@return {Buffer}       A single buffer that is an encoded concatentation of buffs
Combine an array of buffers into a single buffer encoded such that they can all be extracted again .