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

Statements: 84.38% (27 / 32)      Branches: 50% (4 / 8)      Functions: 100% (4 / 4)      Lines: 84.38% (27 / 32)      Ignored: none     

All files » streaming-cache/lib/ » CacheDuplexStream.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 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72    1 1 1   1   1 19 19 19   19 19 19 6               1 8                   8                                 1 14 14   14 2 2 2   12 12 12       14     1  
'use strict';
 
var util = require('util');
var Duplex = require('stream').Duplex;
var LinkedList = require('linkedlist');
 
util.inherits(CacheDuplexStream, Duplex);
 
function CacheDuplexStream(buffer, emitter) {
    Duplex.call(this);
	this.emitter = emitter;
	this._offset = 0;
    // this.chunks = new LinkedList();
    this.unfullfilledReadCount = 0;
	this.readOffset = 0;
    this.on('finish', function onFinish() {
        Iif (this.unfullfilledReadCount > 0) {
            this.push(null);
        // } else {
        //     this.chunks.push(null);
        }
    });
}
 
CacheDuplexStream.prototype._read = function _read(size) {
	Iif(this.readOffset < this.emitter._buffer.length) {
		var chunk = this.emitter._buffer[this.readOffset];
		this.readOffset++
 
	// if (this.chunks.length) {
    //     var chunk = this.chunks.shift();
 
		this.push(chunk);
        this.unfullfilledReadCount =  (this.unfullfilledReadCount > 0) ? this.unfullfilledReadCount - 1 : this.unfullfilledReadCount;
    } else {
        this.unfullfilledReadCount = this.unfullfilledReadCount + 1;
    }
	//
	// size = size || 24 * 1024;
    // size = Math.min(size, this._object.length - this._offset);
	//
	// var buffer = Buffer.concat(self.emitters[key]._buffer);
	//
    // if (this._offset < buffer.length) {
    //     this.push(buffer.slice(this._offset, this._offset + size));
    //     this._offset += size;
    // }
 
 
 
};
 
CacheDuplexStream.prototype._write = function _write(chunk, encoding, next) {
	this.emitter._buffer.push(chunk);
	this.emitter.emit('data', chunk);
 
	if (this.unfullfilledReadCount > 0) {
		this.readOffset++;
		this.push(chunk);
        this.unfullfilledReadCount =  this.unfullfilledReadCount - 1;
    } else {
		this.readOffset++;
		this.push(chunk);
        this.unfullfilledReadCount =  this.unfullfilledReadCount - 1;
 
		// this.chunks.push(chunk);
    }
    next();
};
 
module.exports = CacheDuplexStream;