BufferList.js 385 B

1234567891011121314151617181920212223242526
  1. module.exports = BufferList;
  2. function BufferList() {
  3. this.bufs = [];
  4. this.size = 0;
  5. }
  6. BufferList.prototype.shift = function shift() {
  7. var buf = this.bufs.shift();
  8. if (buf) {
  9. this.size -= buf.length;
  10. }
  11. return buf;
  12. };
  13. BufferList.prototype.push = function push(buf) {
  14. if (!buf || !buf.length) {
  15. return;
  16. }
  17. this.bufs.push(buf);
  18. this.size += buf.length;
  19. };