提交 4b1eb855 编写于 作者: P Parsa Ghadimi 提交者: Ryan Dahl

Make fetch.blob() work

上级 662e57b2
......@@ -20,6 +20,7 @@ import {
FormData
} from "./dom_types";
import { TextDecoder } from "./text_encoding";
import { DenoBlob } from "./blob";
interface Header {
name: string;
......@@ -134,8 +135,10 @@ class FetchResponse implements Response {
}
async blob(): Promise<Blob> {
notImplemented();
return {} as Blob;
const arrayBuffer = await this.arrayBuffer();
return new DenoBlob([arrayBuffer], {
type: this.headers.get("content-type") || ""
});
}
async formData(): Promise<FormData> {
......
......@@ -35,3 +35,11 @@ test(async function headersAppend() {
}
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")));
});
......@@ -9,7 +9,7 @@ export function setLogDebug(debug: boolean): void {
}
/**
* Debug logging for deno.
* Debug logging for deno.
* Enable with the `--log-debug` or `-D` command line flag.
* @internal
*/
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册