Skip to content
Prev Previous commit
Next Next commit
fixup! add tests
  • Loading branch information
debadree25 committed Feb 16, 2023
commit bcd122a620e8a8f658e2e96b5bce3324f841bc27
32 changes: 27 additions & 5 deletions lib/internal/streams/compose.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,18 +42,32 @@ module.exports = function compose(...streams) {
}

for (let n = 0; n < streams.length; ++n) {
if (!isNodeStream(streams[n])) {
if (!isNodeStream(streams[n]) && !isWebStream(streams[n])) {
// TODO(ronag): Add checks for non streams.
continue;
}
if (n < streams.length - 1 && !isReadable(streams[n])) {
if (
n < streams.length - 1 &&
!(
isReadable(streams[n]) ||
isReadableStream(streams[n]) ||
isTransformStream(streams[n])
)
) {
throw new ERR_INVALID_ARG_VALUE(
`streams[${n}]`,
orgStreams[n],
'must be readable'
);
}
if (n > 0 && !isWritable(streams[n])) {
if (
n > 0 &&
!(
isWritable(streams[n]) ||
isWritableStream(streams[n]) ||
isTransformStream(streams[n])
)
) {
throw new ERR_INVALID_ARG_VALUE(
`streams[${n}]`,
orgStreams[n],
Expand Down Expand Up @@ -83,8 +97,16 @@ module.exports = function compose(...streams) {
const head = streams[0];
const tail = pipeline(streams, onfinished);

const writable = !!(isWritable(head) || isWritableStream(head) || isTransformStream(head));
const readable = !!(isReadable(tail) || isReadableStream(tail) || isTransformStream(tail));
const writable = !!(
isWritable(head) ||
isWritableStream(head) ||
isTransformStream(head)
);
const readable = !!(
isReadable(tail) ||
isReadableStream(tail) ||
isTransformStream(tail)
);

// TODO(ronag): Avoid double buffering.
// Implement Writable/Readable/Duplex traits.
Expand Down
Loading