Re: [w3c/FileAPI] Add simpler reading methods to Blob interface. (#117)

annevk approved this pull request.

Looks good to me % nits. With tests and implementation bugs this'll be a great addition to the platform. Hopefully everyone picks it up quickly.

> @@ -228,6 +231,11 @@ interface Blob {
   Blob slice(optional [Clamp] long long start,
             optional [Clamp] long long end,
             optional DOMString contentType);
+
+  // read from the Blob.
+  ReadableStream stream();
+  Promise<USVString> text();
+  Promise<ArrayBuffer> arrayBuffer();

These can all be annotated with `[NewObject]`. Filed #121 for the remainder.

> +The <dfn method for=Blob>stream()</dfn> method, when invoked, must return
+the result of calling [=get stream=] on the [=context object=].
+
+### The {{Blob/text()}} method ### {#text-method-algo}
+
+The <dfn method for=Blob>text()</dfn> method, when invoked, must run these steps:
+
+1. Let |stream| be the result of calling [=get stream=] on the [=context object=].
+1. Let |reader| be the result of [=get a reader|getting a reader=] from |stream|.
+   If that threw an exception, return a new promise rejected with that exception.
+1. Let |promise| be the result of [=read all bytes|reading all bytes=] from |stream| with |reader|.
+1. Return the result of transforming |promise| by a fulfillment handler that returns the result of
+   running [=UTF-8 decode=] on its first argument.
+
+Note: This is different from the behavior of {{FileReader/readAsText()}} to align better
+with the behavior of {{Body/text()|Body.text()}}. Specifically this method will always

I'd make the link text something like "Fetch's text()" for clarity. Body is just a specification mechanism.

-- 
You are receiving this because you are subscribed to this thread.
Reply to this email directly or view it on GitHub:
https://github.com/w3c/FileAPI/pull/117#pullrequestreview-215308798

Received on Saturday, 16 March 2019 09:58:03 UTC