I have a situation where I want a sub-stream (in same manner as a
sub-string) of a ReadableStream to be treated as a different stream
entirely.
Currently I have the following:
```
//
// Create a stream that consumes a future part an existing stream
//
var ReadableStream = require('readable-stream');
function subStream(origin, length, pad) {
var stream = new ReadableStream({allowHalfOpen: false});
stream._read = function (size, cb) {
if (!length) {
stream._readableState.ended = true;
cb(null, null);
return;
}
var data = origin.read(Math.min(size, length));
if (data) {
length -= data.length;
}
cb(null, data);
}
return stream;
}
exports.subStream = subStream;
```
but am unable to determine how to end it properly after reading some docs
in readable-stream and in the code I am still confused as to how to tell
_read that the stream is done without forcing extra read()s to be done by
the user when they would have no reason to do so. Any help in understanding
_read's ending system would be greatly appreciated.
--
Job Board: http://jobs.nodejs.org/
Posting guidelines:
https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines
You received this message because you are subscribed to the Google
Groups "nodejs" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/nodejs?hl=en?hl=en