npmtest-msgpack-lite (v0.0.2)

Code coverage report for node-npmtest-msgpack-lite/node_modules/msgpack-lite/lib/encode-stream.js

Statements: 36% (9 / 25)      Branches: 0% (0 / 8)      Functions: 0% (0 / 4)      Lines: 40.91% (9 / 22)      Ignored: none     

All files » node-npmtest-msgpack-lite/node_modules/msgpack-lite/lib/ » encode-stream.js
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39    1   1 1 1   1   1   1                               1         1          
// encode-stream.js
 
exports.createEncodeStream = EncodeStream;
 
var util = require("util");
var Transform = require("stream").Transform;
var EncodeBuffer = require("./encode-buffer").EncodeBuffer;
 
util.inherits(EncodeStream, Transform);
 
var DEFAULT_OPTIONS = {objectMode: true};
 
function EncodeStream(options) {
  if (!(this instanceof EncodeStream)) return new EncodeStream(options);
  if (options) {
    options.objectMode = true;
  } else {
    options = DEFAULT_OPTIONS;
  }
  Transform.call(this, options);
 
  var stream = this;
  var encoder = this.encoder = new EncodeBuffer(options);
  encoder.push = function(chunk) {
    stream.push(chunk);
  };
}
 
EncodeStream.prototype._transform = function(chunk, encoding, callback) {
  this.encoder.write(chunk);
  if (callback) callback();
};
 
EncodeStream.prototype._flush = function(callback) {
  this.encoder.flush();
  if (callback) callback();
};