Code coverage report for lib/parser/hiredis.js

Statements: 92% (23 / 25)      Branches: 90% (9 / 10)      Functions: 100% (3 / 3)      Lines: 92% (23 / 25)      Ignored: none     

All files » lib/parser/ » hiredis.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 40 41 42 43 44 45 46 473       3 3   3 25 25 25 25     3   3   3 25         3 184 184 184 730 730           730 183     547 12   535        
var events = require("events"),
    util = require("../util"),
    hiredis = require("hiredis");
 
exports.debug_mode = false;
exports.name = "hiredis";
 
function HiredisReplyParser(options) {
    this.name = exports.name;
    this.options = options || {};
    this.reset();
    events.EventEmitter.call(this);
}
 
util.inherits(HiredisReplyParser, events.EventEmitter);
 
exports.Parser = HiredisReplyParser;
 
HiredisReplyParser.prototype.reset = function () {
    this.reader = new hiredis.Reader({
        return_buffers: this.options.return_buffers || false
    });
};
 
HiredisReplyParser.prototype.execute = function (data) {
    var reply;
    this.reader.feed(data);
    while (true) {
        try {
            reply = this.reader.get();
        } catch (err) {
            this.emit("error", err);
            break;
        }
 
        if (reply === undefined) {
            break;
        }
 
        if (reply && reply.constructor === Error) {
            this.emit("reply error", reply);
        } else {
            this.emit("reply", reply);
        }
    }
};