
module.exports = function () {

  var buffers = [], length = 0
  return {
    length: length,
    data: this,
    add: function (data) {
      if(!Buffer.isBuffer(data))
        throw new Error('data must be a buffer, was: ' + JSON.stringify(data))
      this.length = length = length + data.length
      buffers.push(data)
      return this
    },
    has: function (n) {
      if(null == n) return length > 0
      return length - (n || 0) >= 0
    },
    get: function (n) {
      if(n == null || n === length) {
        length = 0
        var _buffers = buffers
        buffers = []
        return Buffer.concat(_buffers)
      } else if(n <= length) {
        var out = [], len = 0
        while((len + buffers[0].length) <= n) {
          var b = buffers.shift()
          len += b.length
          out.push(b)
        }
        if(len < n) {
          out.push(buffers[0].slice(0, n - len))
          buffers[0] = buffers[0].slice(n - len, buffers[0].length)
          this.length = length = length - n
        }
        return Buffer.concat(out)
      }
    }
  }

}

@@ -57,16 +57,160 @@
 gth = 0%0A
+%0A  //just used for debugging...%0A  function calcLength () %7B%0A    return buffers.reduce(function (a, b) %7B%0A      return a + b.length%0A    %7D, 0)%0A  %7D%0A%0A
   return
@@ -572,24 +572,13 @@
 ngth
- - (n %7C%7C 0)
  %3E= 
-0
+n
 %0A   
@@ -772,17 +772,16 @@
 e if(n %3C
-=
  length)
@@ -809,24 +809,25 @@
 %5B%5D, len = 0%0A
+%0A
         whil
@@ -855,17 +855,16 @@
 ength) %3C
-=
  n) %7B%0A  
@@ -945,32 +945,33 @@
 sh(b)%0A        %7D%0A
+%0A
         if(len %3C
@@ -1185,24 +1185,92 @@
 ut)%0A      %7D%0A
+      else%0A        throw new Error('could not get ' + n + ' bytes')%0A
     %7D%0A  %7D%0A%0A%7D

handle edge cases