1.0.0 • Published 9 years ago

thor-stream v1.0.0

Weekly downloads
2
License
MIT
Repository
github
Last release
9 years ago

thor-stream

thor-strem


Unended Stream, useful for piping streams one after another

doc

thorStream(onWrite, onEnd, options) ⇒ stream

Creates a writable and readable stream

Kind: global function
Returns: stream - a simplified stream

ParamTypeDescription
onWritefunctioncallback on data
onEndfunctioncallback on end
optionsobjectsetting autoDestroy will destory stream once stream ended defaults to true, setting thorMode will keep the stream stay long :iywim:

usage

var urls = ['http://x', 'http://y'];

function requestUrl(scrollId, stream) {
    var url = 'http:// sss' + scrollId;
    return request(url)
        .pipe(JSONStream.parse('hits.hits.*'))
        .pipe(stream);
}

var stream = thorStream(function write(data) {
        count++;
        this.emit('data', data);
    },
    function end () {
        //ending the stream if no data received for this
        if(count === 0) {
            this.endThor();
            this.emit('end');
            return;
        }
        count = 0;
        requestUrl(scrollId, stream);
    });