diff options
author | Asher Gomez <ashersaupingomez@gmail.com> | 2024-05-23 10:27:58 +1000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-05-23 00:27:58 +0000 |
commit | 8a636d0600dc7000d1e12b2fc4f4f46ecd70164a (patch) | |
tree | a568fcac6b658e041f15da3b62953a5b812433f6 /ext/fetch/22_body.js | |
parent | f5d0c4b1ea39e34e2e068264f18021a4f7412479 (diff) |
feat(ext/fetch): `Request.bytes()` and `Response.bytes()` (#23823)
Closes #23790
Diffstat (limited to 'ext/fetch/22_body.js')
-rw-r--r-- | ext/fetch/22_body.js | 13 |
1 files changed, 12 insertions, 1 deletions
diff --git a/ext/fetch/22_body.js b/ext/fetch/22_body.js index e16fd4c54..e9d493658 100644 --- a/ext/fetch/22_body.js +++ b/ext/fetch/22_body.js @@ -296,6 +296,15 @@ function mixinBody(prototype, bodySymbol, mimeTypeSymbol) { configurable: true, enumerable: true, }, + bytes: { + /** @returns {Promise<Uint8Array>} */ + value: function bytes() { + return consumeBody(this, "bytes"); + }, + writable: true, + configurable: true, + enumerable: true, + }, formData: { /** @returns {Promise<FormData>} */ value: function formData() { @@ -330,7 +339,7 @@ function mixinBody(prototype, bodySymbol, mimeTypeSymbol) { /** * https://fetch.spec.whatwg.org/#concept-body-package-data * @param {Uint8Array | string} bytes - * @param {"ArrayBuffer" | "Blob" | "FormData" | "JSON" | "text"} type + * @param {"ArrayBuffer" | "Blob" | "FormData" | "JSON" | "text" | "bytes"} type * @param {MimeType | null} [mimeType] */ function packageData(bytes, type, mimeType) { @@ -341,6 +350,8 @@ function packageData(bytes, type, mimeType) { return new Blob([bytes], { type: mimeType !== null ? mimesniff.serializeMimeType(mimeType) : "", }); + case "bytes": + return chunkToU8(bytes); case "FormData": { if (mimeType !== null) { const essence = mimesniff.essence(mimeType); |