Skip to content

Commit f2e02ce

Browse files
committed
Revert "Remove readStream() helper"
This reverts commit 7611f2f.
1 parent 4914bee commit f2e02ce

File tree

4 files changed

+11
-8
lines changed

4 files changed

+11
-8
lines changed

packages/node-fetch-server/CHANGELOG.md

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,6 @@
22

33
This is the changelog for [`node-fetch-server`](https://github.com/mjackson/remix-the-web/tree/main/packages/node-fetch-server). It follows [semantic versioning](https://semver.org/).
44

5-
## HEAD
6-
7-
- Remove internal `readStream()` helper and use async iterator directly
8-
95
## v0.7.0 (2025-06-06)
106

117
- Add `/src` to npm package, so "go to definition" goes to the actual source

packages/node-fetch-server/global.d.ts

Lines changed: 0 additions & 3 deletions
This file was deleted.
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
export async function* readStream(stream: ReadableStream<Uint8Array>): AsyncIterable<Uint8Array> {
2+
let reader = stream.getReader();
3+
4+
while (true) {
5+
const { done, value } = await reader.read();
6+
if (done) break;
7+
yield value;
8+
}
9+
}

packages/node-fetch-server/src/lib/request-listener.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import type * as http from 'node:http';
22
import type * as http2 from 'node:http2';
33

44
import type { ClientAddress, ErrorHandler, FetchHandler } from './fetch-handler.ts';
5+
import { readStream } from './read-stream.ts';
56

67
export interface RequestListenerOptions {
78
/**
@@ -214,7 +215,7 @@ export async function sendResponse(
214215
res.writeHead(response.status, headers);
215216

216217
if (response.body != null && res.req.method !== 'HEAD') {
217-
for await (let chunk of response.body) {
218+
for await (let chunk of readStream(response.body)) {
218219
// @ts-expect-error - Node typings for http2 require a 2nd parameter to write but it's optional
219220
res.write(chunk);
220221
}

0 commit comments

Comments
 (0)