diff options
author | 2023-07-19 23:12:06 -0700 | |
---|---|---|
committer | 2023-07-19 23:12:06 -0700 | |
commit | dd46c11273211601bb67eff04dde7279fff5b8d5 (patch) | |
tree | 4251aa7cd12af02a471cad311239c5c86b3613ed /src/js/builtins/ReadableStream.ts | |
parent | 8a13e024734f1571e294a72f5a0ab2835eac4b8f (diff) | |
download | bun-dd46c11273211601bb67eff04dde7279fff5b8d5.tar.gz bun-dd46c11273211601bb67eff04dde7279fff5b8d5.tar.zst bun-dd46c11273211601bb67eff04dde7279fff5b8d5.zip |
Support streams in response.formData() & request.formData, introduce Bun.readableStreamToFormData() (#3697)
* codegen
* FormData.from
* Fixes #3225
* Introduce `Bun.readableStreamToFormData`
* Update bun.d.ts
* Add examples
* add
---------
Co-authored-by: Jarred Sumner <709451+Jarred-Sumner@users.noreply.github.com>
Diffstat (limited to 'src/js/builtins/ReadableStream.ts')
-rw-r--r-- | src/js/builtins/ReadableStream.ts | 10 |
1 files changed, 10 insertions, 0 deletions
diff --git a/src/js/builtins/ReadableStream.ts b/src/js/builtins/ReadableStream.ts index 5a5b7e119..419a8e696 100644 --- a/src/js/builtins/ReadableStream.ts +++ b/src/js/builtins/ReadableStream.ts @@ -149,6 +149,16 @@ export function readableStreamToArrayBuffer(stream: ReadableStream<ArrayBuffer>) } $linkTimeConstant; +export function readableStreamToFormData( + stream: ReadableStream<ArrayBuffer>, + contentType: string | ArrayBuffer | ArrayBufferView, +): Promise<FormData> { + return Bun.readableStreamToBlob(stream).then(blob => { + return FormData.from(blob, contentType); + }); +} + +$linkTimeConstant; export function readableStreamToJSON(stream: ReadableStream): unknown { return Bun.readableStreamToText(stream).$then(globalThis.JSON.parse); } |