How to use the concat-stream.prototype function in concat-stream

To help you get started, we’ve selected a few concat-stream examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github google / dorusu-js / lib / codec.js View on Github external
/**
 * MsgHeaderStream is a `Writable` that concatenates strings or `Buffer`
 * and invokes a callback with an `Buffer` prepended by its length.
 *
 * @param {object} opts options for determining how the data is written
 * @param {function} callback is invoked when all data has been written
 * @constructor
 */
function MsgHeaderStream(opts, callback) {
  // Initializes the base class with the buffer
  this.opts = opts || {};
  ConcatStream.call(this, { encoding: 'buffer' }, callback);
  this.size = 0;
}
MsgHeaderStream.prototype = Object.create(
  ConcatStream.prototype, {constructor: {value: MsgHeaderStream }});

/**
 * Overrides ConcatStream._write to count the size of data in bytes.
 */
MsgHeaderStream.prototype._write = function(chunk, enc, next) {
  this.body.push(chunk);
  this.size += chunk.length;
  next();
};

/**
 * Overrides `ConcatStream.getBody` to return the body prefixed with the
 * size.
 *
 * @returns {external:Buffer} containing the data written to this stream
 *                            prefixed with its length

concat-stream

writable stream that concatenates strings or binary data and calls a callback with the result

MIT
Latest version published 5 years ago

Package Health Score

74 / 100
Full package analysis