grpc-promise
Version:
GRPC promisify module for all Request/Response types: standard and stream
26 lines (21 loc) • 624 B
JavaScript
const stream = require('stream');
const util = require('util');
const ClientStreamMock = function (options) {
if (options == null) {
options = {};
}
stream.Writable.call(this, {objectMode: true});
this.readArr = [];
this.callback = options.callback;
this.on('finish', function () {
if (typeof options.callback === 'function') {
options.callback(null, this.readArr[this.readArr.length - 1]);
}
});
};
util.inherits(ClientStreamMock, stream.Writable);
ClientStreamMock.prototype._write = function (chunk, enc, cb) {
this.readArr.push(chunk);
cb();
};
module.exports = ClientStreamMock;