Skip to content

Commit

Permalink
fix(stream): improve node.js redable stream check
Browse files Browse the repository at this point in the history
avoid false detection of server response as readable stream
  • Loading branch information
pi0 committed Aug 1, 2023
1 parent 7b18fa0 commit cdd2680
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/utils/response.ts
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ export function isStream(data: any): data is Readable | ReadableStream {
return false;
}
// Node.js Readable Streams
if (typeof data.pipe === "function" && typeof data.on === "function") {
if (typeof data.pipe === "function" && typeof data._read === "function") {
return true;
}
// Web Streams
Expand Down Expand Up @@ -227,7 +227,7 @@ export function sendStream(

// Node.js Readable streams
// https://nodejs.org/api/stream.html#readable-streams
if ("pipe" in stream) {
if ("pipe" in stream && "_read" in stream) {
return new Promise<void>((resolve, reject) => {
stream.pipe(event.node.res);
stream.on("end", () => {
Expand Down

0 comments on commit cdd2680

Please sign in to comment.