Sha256: 5f3dfbce0e8b2d20ffab64e66822d5adb972242b2b43bf93d498811ca5d71af5

Contents?: true

Size: 822 Bytes

Versions: 7

Compression:

Stored size: 822 Bytes

Contents

var Readable = require('readable-stream').Readable;

module.exports = function (stream) {
    var opts = stream._readableState;
    if (typeof stream.read !== 'function') {
        stream = new Readable(opts).wrap(stream);
    }
    
    var ro = new Readable({ objectMode: opts && opts.objectMode });
    var waiting = false;
    
    stream.on('readable', function () {
        if (waiting) {
            waiting = false;
            ro._read();
        }
    });
    
    ro._read = function () {
        var buf, reads = 0;
        while ((buf = stream.read()) !== null) {
            ro.push(buf);
            reads ++;
        }
        if (reads === 0) waiting = true;
    };
    stream.once('end', function () { ro.push(null) });
    stream.on('error', function (err) { ro.emit('error', err) });
    return ro;
};

Version data entries

7 entries across 7 versions & 2 rubygems

Version Path
minimum_viable_product-0.0.11 test/dummy/node_modules/read-only-stream/index.js
brwy_rails-0.0.6 test/dummy/node_modules/read-only-stream/index.js
brwy_rails-0.0.5 test/dummy/node_modules/read-only-stream/index.js
brwy_rails-0.0.4 test/dummy/node_modules/read-only-stream/index.js
brwy_rails-0.0.3 test/dummy/node_modules/read-only-stream/index.js
brwy_rails-0.0.2 test/dummy/node_modules/read-only-stream/index.js
brwy_rails-0.0.1 test/dummy/node_modules/read-only-stream/index.js