Skip to content

Commit 1904af0

Browse files
authored
Ensure toArrayStream always returns an ArrayStream (#61)
Throw in `toArrayStream` when passing a non-`ArrayStream` stream, to ensure that it always returns an `ArrayStream`. When converting between stream types, call `readToEnd` first.
1 parent 256dcde commit 1904af0

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

lib/streams.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,11 @@ function toStream(input) {
2525
* @returns {ArrayStream} Converted data
2626
*/
2727
function toArrayStream(input) {
28-
if (isStream(input)) {
28+
const streamType = isStream(input);
29+
if (streamType) {
30+
if (streamType !== 'array') {
31+
throw new Error("Can't convert Stream to ArrayStream here, call `readToEnd` first");
32+
}
2933
return input;
3034
}
3135
const stream = new ArrayStream();

0 commit comments

Comments
 (0)