-
-
Notifications
You must be signed in to change notification settings - Fork 2.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Stream request body instead of buffering it in memory (#8084)
Co-authored-by: Matthew Phillips <[email protected]>
- Loading branch information
Showing
3 changed files
with
59 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
16 changes: 16 additions & 0 deletions
16
packages/adapters/node/test/fixtures/api-route/src/pages/hash.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import crypto from 'node:crypto'; | ||
|
||
export async function post({ request }: { request: Request }) { | ||
const hash = crypto.createHash('sha256'); | ||
|
||
const iterable = request.body as unknown as AsyncIterable<Uint8Array>; | ||
for await (const chunk of iterable) { | ||
hash.update(chunk); | ||
} | ||
|
||
return new Response(hash.digest(), { | ||
headers: { | ||
'Content-Type': 'application/octet-stream' | ||
} | ||
}); | ||
} |