Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(ext/fetch): Request.bytes() and Response.bytes() #23823

Merged
merged 14 commits into from
May 23, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions cli/tsc/dts/lib.dom.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3156,6 +3156,7 @@ interface Body {
arrayBuffer(): Promise<ArrayBuffer>;
/** [MDN Reference](https://developer.mozilla.org/docs/Web/API/Request/blob) */
blob(): Promise<Blob>;
bytes(): Promise<Uint8Array>;
iuioiua marked this conversation as resolved.
Show resolved Hide resolved
/** [MDN Reference](https://developer.mozilla.org/docs/Web/API/Request/formData) */
formData(): Promise<FormData>;
/** [MDN Reference](https://developer.mozilla.org/docs/Web/API/Request/json) */
Expand Down
1 change: 1 addition & 0 deletions cli/tsc/dts/lib.webworker.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1029,6 +1029,7 @@ interface Body {
arrayBuffer(): Promise<ArrayBuffer>;
/** [MDN Reference](https://developer.mozilla.org/docs/Web/API/Request/blob) */
blob(): Promise<Blob>;
bytes(): Promise<Uint8Array>;
iuioiua marked this conversation as resolved.
Show resolved Hide resolved
/** [MDN Reference](https://developer.mozilla.org/docs/Web/API/Request/formData) */
formData(): Promise<FormData>;
/** [MDN Reference](https://developer.mozilla.org/docs/Web/API/Request/json) */
Expand Down
13 changes: 12 additions & 1 deletion ext/fetch/22_body.js
Original file line number Diff line number Diff line change
Expand Up @@ -296,6 +296,15 @@ function mixinBody(prototype, bodySymbol, mimeTypeSymbol) {
configurable: true,
enumerable: true,
},
bytes: {
/** @returns {Promise<Uint8Array>} */
value: function bytes() {
return consumeBody(this, "bytes");
iuioiua marked this conversation as resolved.
Show resolved Hide resolved
},
writable: true,
configurable: true,
enumerable: true,
},
formData: {
/** @returns {Promise<FormData>} */
value: function formData() {
Expand Down Expand Up @@ -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) {
Expand All @@ -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);
Expand Down
4 changes: 4 additions & 0 deletions ext/fetch/lib.deno_fetch.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,10 @@ declare interface Body {
* that resolves with a `Blob`.
*/
blob(): Promise<Blob>;
/** Takes a `Response` stream and reads it to completion. It returns a promise
* that resolves with a `Uint8Array`.
*/
bytes(): Promise<Uint8Array>;
/** Takes a `Response` stream and reads it to completion. It returns a promise
* that resolves with a `FormData` object.
*/
Expand Down
2 changes: 2 additions & 0 deletions tests/wpt/runner/expectation.json
Original file line number Diff line number Diff line change
Expand Up @@ -7112,6 +7112,8 @@
"response": {
"json.any.html": true,
"json.any.worker.html": true,
"response-blob-realm.any.html": true,
"response-blob-realm.any.worker.html": true,
"response-init-001.any.html": true,
"response-init-001.any.worker.html": true,
"response-init-002.any.html": true,
Expand Down
2 changes: 1 addition & 1 deletion tests/wpt/suite
Submodule suite updated 1877 files