-
Notifications
You must be signed in to change notification settings - Fork 29.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
stream.compose does not preserve 'readableObjectMode' from final stream to returned stream #46829
Comments
I'm assuming this is just a typo on this line: node/lib/internal/streams/compose.js Line 91 in 347215e
|
You should use https://nodejs.org/dist/latest-v18.x/docs/api/stream.html#readablereadsize
|
That's absolutely true for non-object-mode streams, but I'm confident that's not expected for an object mode stream. I think the code above just should be -readableObjectMode: !!tail?.writableObjectMode,
+readableObjectMode: !!tail?.readableObjectMode, |
I don't understand, the transform stream needs to be both readable and writable in object mode. Otherwise the returned stream (the one the transform is writing into) isn't in object mode (the return stream isn't in writableObjectMode anyway). The example works if you add |
Can you clarify what you mean by that? I know my transform stream could be a writable object stream, but I don't think it's required or expected that anything that is readable-object-mode must be in writable-object-mode. In this case I'm expecting the transform to take in a byte stream and produce and object stream, essentially. I'd expect that compose would return a stream that is:
|
I agree with @loganfsmyth and it is expected IMO given that a Transform can get bytes and write object
This logs the data: let readInByteWriteInObject = new Transform({
// reading FROM you in object mode or not
readableObjectMode: true,
// writing TO you in object mode or not
writableObjectMode: false,
transform: function (value, enc, callback) {
callback(null, {
data: value
});
},
});
readInByteWriteInObject.on('data', (data) => {
console.log(data);
});
readInByteWriteInObject.write('0 1 2 3 4') but this does not: let readInByteWriteInObject = new Transform({
// reading FROM you in object mode or not
readableObjectMode: true,
// writing TO you in object mode or not
writableObjectMode: false,
transform: function (value, enc, callback) {
callback(null, {
data: value
});
},
});
const s = Readable.from("0 1 2 3 4", {objectMode: false})
.compose(
readInByteWriteInObject
);
s.on('data', (data) => {
console.log(data);
}); |
Fixes: #46829 PR-URL: #47413 Reviewed-By: Robert Nagy <[email protected]> Reviewed-By: Benjamin Gruenbaum <[email protected]> Reviewed-By: Matteo Collina <[email protected]>
Fixes: #46829 PR-URL: #47413 Reviewed-By: Robert Nagy <[email protected]> Reviewed-By: Benjamin Gruenbaum <[email protected]> Reviewed-By: Matteo Collina <[email protected]>
Fixes: nodejs#46829 PR-URL: nodejs#47413 Reviewed-By: Robert Nagy <[email protected]> Reviewed-By: Benjamin Gruenbaum <[email protected]> Reviewed-By: Matteo Collina <[email protected]>
that includes a fix to nodejs/node#46829
that includes a fix to nodejs/node#46829
Version
v19.7.0
Platform
No response
Subsystem
No response
What steps will reproduce the bug?
How often does it reproduce? Is there a required condition?
No response
What is the expected behavior?
Should output
What do you see instead?
Additional information
No response
The text was updated successfully, but these errors were encountered: