event-message-unmarshaller-stream.js
975 Bytes
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
var Transform = require('stream').Transform;
var parseEvent = require('./parse-event').parseEvent;
/** @type {Transform} */
function EventUnmarshallerStream(options) {
options = options || {};
// set output to object mode
options.readableObjectMode = true;
Transform.call(this, options);
this._readableState.objectMode = true;
this.parser = options.parser;
this.eventStreamModel = options.eventStreamModel;
}
EventUnmarshallerStream.prototype = Object.create(Transform.prototype);
/**
*
* @param {Buffer} chunk
* @param {string} encoding
* @param {*} callback
*/
EventUnmarshallerStream.prototype._transform = function(chunk, encoding, callback) {
try {
var event = parseEvent(this.parser, chunk, this.eventStreamModel);
this.push(event);
return callback();
} catch (err) {
callback(err);
}
};
/**
* @api private
*/
module.exports = {
EventUnmarshallerStream: EventUnmarshallerStream
};