summaryrefslogtreecommitdiff
path: root/js
diff options
context:
space:
mode:
authorParsa Ghadimi <me@qti3e.com>2018-09-14 22:26:37 +0430
committerRyan Dahl <ry@tinyclouds.org>2018-09-14 12:50:32 -0700
commit4b1eb855bf8fa33b802f5be67c93217eb582bc24 (patch)
tree52165e354043494dad5856aa768939fc4fcacc7c /js
parent662e57b20adc7bbb7037c116f8f72678017db94e (diff)
Make fetch.blob() work
Diffstat (limited to 'js')
-rw-r--r--js/fetch.ts7
-rw-r--r--js/fetch_test.ts8
-rw-r--r--js/util.ts2
3 files changed, 14 insertions, 3 deletions
diff --git a/js/fetch.ts b/js/fetch.ts
index 4f225b507..48429ca19 100644
--- a/js/fetch.ts
+++ b/js/fetch.ts
@@ -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> {
diff --git a/js/fetch_test.ts b/js/fetch_test.ts
index 2b7f32099..25d8c2ed0 100644
--- a/js/fetch_test.ts
+++ b/js/fetch_test.ts
@@ -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")));
+});
diff --git a/js/util.ts b/js/util.ts
index c4bada589..bfde01908 100644
--- a/js/util.ts
+++ b/js/util.ts
@@ -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
*/