Code coverage report for lib/readStream.js

Statements: 28.57% (10 / 35)      Branches: 0% (0 / 15)      Functions: 0% (0 / 5)      Lines: 29.41% (10 / 34)      Ignored: none     

All files » lib/ » readStream.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 51 52 53 54    1 1   1   1             1           1       1   1                                           1       1  
'use strict';
 
var util = require('util');
var Readable = require('stream').Readable;
 
util.inherits(ReadStream, Readable);
 
function ReadStream() {
    Readable.call(this);
    this._offset = 0;
    this.readable = false;
    this._object = new Buffer(0);
}
 
ReadStream.prototype.setBuffer = function (_object) {
    this.complete = true;
    this._object = _object;
    this._push();
};
 
ReadStream.prototype.updateBuffer = function (_object) {
    this._object = _object;
};
 
ReadStream.prototype.complete = false;
 
ReadStream.prototype._push = function (size) {
    if (this.ended) {
        return;
    }
    if (this.complete && this._offset === this._object.length && !this._readableState.ended) {
        this.push(null);
        this.ended = true;
        return;
    }
    if (!size) {size =  24 * 1024;}
    if (!this._object.length) {
        return;
    }
    if (this._offset + size > this._object.length) {
        size = this._object.length - this._offset;
    }
    if (this._offset < this._object.length) {
        var offset = this._offset;
        this._offset += size ;
        this.push(this._object.slice(offset, (offset + size)));
    }
};
ReadStream.prototype._read = function (size) {
    this._push(size);
};
 
module.exports = ReadStream;