Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
Download
80522 views
1
var Readable = require('readable-stream/readable');
2
var rwrap = require('readable-wrap');
3
4
module.exports = function (stream) {
5
var opts = stream._readableState;
6
if (typeof stream.read !== 'function') stream = rwrap(stream, opts);
7
8
var ro = new Readable({ objectMode: opts && opts.objectMode });
9
var waiting = false;
10
11
stream.on('readable', function () {
12
if (waiting) {
13
waiting = false;
14
ro._read();
15
}
16
});
17
18
ro._read = function () {
19
var buf, reads = 0;
20
while ((buf = stream.read()) !== null) {
21
ro.push(buf);
22
reads ++;
23
}
24
if (reads === 0) waiting = true;
25
};
26
stream.once('end', function () { ro.push(null) });
27
stream.on('error', function (err) { ro.emit('error', err) });
28
return ro;
29
};
30
31