Why Gemfury? Push, build, and install  RubyGems npm packages Python packages Maven artifacts PHP packages Go Modules Debian packages RPM packages NuGet packages

Repository URL to install this package:

Details    
Size: Mime:
"use strict";

// https://github.com/JacksonTian/bufferhelper
let BufferHelper = function BufferHelper() {
  this.buffers = [];
  this.size = 0;
  Object.defineProperty(this, 'length', {
    get() {
      return this.size;
    }

  });
};

BufferHelper.prototype.concat = function (buffer) {
  this.buffers.push(buffer);
  this.size += buffer.length;
  return this;
};

BufferHelper.prototype.empty = function () {
  this.buffers = [];
  this.size = 0;
  return this;
};

BufferHelper.prototype.toBuffer = function () {
  return Buffer.concat(this.buffers, this.size);
};

BufferHelper.prototype.toString = function (encoding) {
  return this.toBuffer().toString(encoding);
};

BufferHelper.prototype.load = function (stream, callback) {
  let that = this;
  stream.on('data', function (trunk) {
    that.concat(trunk);
  });
  stream.on('end', function () {
    callback(null, that.toBuffer());
  });
  stream.once('error', callback);
};

module.exports = BufferHelper;