Code coverage report for streaming-cache/lib/PendingReadStream.js

Statements: 80.65% (25 / 31)      Branches: 64.29% (9 / 14)      Functions: 100% (4 / 4)      Lines: 80.65% (25 / 31)      Ignored: none     

All files » streaming-cache/lib/ » PendingReadStream.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 47 48 49 50    1 1   1   1 3 3 3 3 3 3     1   5 4 4 4 4   1   5         1 5                   1 2 1   2   1  
'use strict';
 
var util = require('util');
var Readable = require('stream').Readable;
 
util.inherits(PendingReadStream, Readable);
 
function PendingReadStream(buffer) {
    Readable.call(this);
    this._buffer = buffer;
    this.unfullfilledReadCount = 0;
    this._offset = 0;
    this.readOffset = 0;
    this._ended = false;
}
 
PendingReadStream.prototype._read = function _read() {
    // console.log('_read', this.readOffset , this._buffer.length);
    if (this.readOffset <= this._buffer.length) {
        var chunk = this._buffer[this.readOffset];
        this.readOffset++;
        this.push(chunk);
        this.unfullfilledReadCount =  (this.unfullfilledReadCount > 0) ? this.unfullfilledReadCount - 1 : this.unfullfilledReadCount;
    } else {
        this.unfullfilledReadCount = this.unfullfilledReadCount + 1;
    }
    Iif (this.readOffset === this._buffer.length && this._ended) {
        this.push(null);
    }
};
 
PendingReadStream.prototype.update = function update() {
    Iif (this.unfullfilledReadCount > 0) {
        if (this.readOffset < this._buffer.length) {
            var chunk = this._buffer[this.readOffset ];
 
            this.readOffset++;
            this.push(chunk);
            this.unfullfilledReadCount =  this.unfullfilledReadCount - 1;
        }
    }
};
PendingReadStream.prototype._end = function end() {
    if (this.unfullfilledReadCount === 0) {
		this.push(null);
    }
    this._ended = true;
};
module.exports = PendingReadStream;