"use strict";var StreamReader=function(){this._queue=[],this._queueSize=0,this._offset=0};StreamReader.prototype.put=function(e){e&&0!==e.length&&(e.copy||(e=new Buffer(e)),this._queue.push(e),this._queueSize+=e.length)},StreamReader.prototype.read=function(e){if(e>this._queueSize)return null;if(0===e)return new Buffer(0);this._queueSize-=e;var t,r,u=this._queue,i=e,n=u[0];if(n.length>=e)return n.length===e?u.shift():(r=n.slice(0,e),u[0]=n.slice(e),r);for(var f=0,h=u.length;f<h&&!(i<u[f].length);f++)i-=u[f].length;return t=u.splice(0,f),i>0&&u.length>0&&(t.push(u[0].slice(0,i)),u[0]=u[0].slice(i)),this._concat(t,e)},StreamReader.prototype.eachByte=function(e,t){for(var r,u,i;this._queue.length>0;){for(u=(r=this._queue[0]).length;this._offset<u;)i=this._offset,this._offset+=1,e.call(t,r[i]);this._offset=0,this._queue.shift()}},StreamReader.prototype._concat=function(e,t){if(Buffer.concat)return Buffer.concat(e,t);for(var r=new Buffer(t),u=0,i=0,n=e.length;i<n;i++)e[i].copy(r,u),u+=e[i].length;return r},module.exports=StreamReader;