mirror of
https://github.com/denoland/deno.git
synced 2025-03-03 17:34:47 -05:00
Make fetch.blob() work
This commit is contained in:
parent
662e57b20a
commit
4b1eb855bf
3 changed files with 14 additions and 3 deletions
|
@ -20,6 +20,7 @@ import {
|
||||||
FormData
|
FormData
|
||||||
} from "./dom_types";
|
} from "./dom_types";
|
||||||
import { TextDecoder } from "./text_encoding";
|
import { TextDecoder } from "./text_encoding";
|
||||||
|
import { DenoBlob } from "./blob";
|
||||||
|
|
||||||
interface Header {
|
interface Header {
|
||||||
name: string;
|
name: string;
|
||||||
|
@ -134,8 +135,10 @@ class FetchResponse implements Response {
|
||||||
}
|
}
|
||||||
|
|
||||||
async blob(): Promise<Blob> {
|
async blob(): Promise<Blob> {
|
||||||
notImplemented();
|
const arrayBuffer = await this.arrayBuffer();
|
||||||
return {} as Blob;
|
return new DenoBlob([arrayBuffer], {
|
||||||
|
type: this.headers.get("content-type") || ""
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
async formData(): Promise<FormData> {
|
async formData(): Promise<FormData> {
|
||||||
|
|
|
@ -35,3 +35,11 @@ test(async function headersAppend() {
|
||||||
}
|
}
|
||||||
assert(err instanceof TypeError);
|
assert(err instanceof TypeError);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
testPerm({ net: true }, async function fetchBlob() {
|
||||||
|
const response = await fetch("http://localhost:4545/package.json");
|
||||||
|
const headers = response.headers;
|
||||||
|
const blob = await response.blob();
|
||||||
|
assertEqual(blob.type, headers.get("Content-Type"));
|
||||||
|
assertEqual(blob.size, Number(headers.get("Content-Length")));
|
||||||
|
});
|
||||||
|
|
Loading…
Add table
Reference in a new issue