[w3c/FileAPI] Consider Blob.fromStream (returns a Promise<Blob>) (#140)

I'm filing this as a tracking issue, although I don't think it's particularly urgent. But maybe web developers have run into this more, in which case hearing from them would be great.

Anyway, right now, to convert a `ReadableStream` to a `Blob`, you have to do

```
const blob = await new Response(stream).blob();
```

which is pretty silly. Just as `blob.stream()` was added to avoid the silly `new Request(blob).body` pattern, perhaps we should consider adding a promise-returning `Blob.fromStream()` so you could do

```js
const blob = await Blob.fromStream(stream);
```

This is a bigger savings if we add an `options` parameter:

```js
const blob1 = new Blob([await new Response(stream).blob()], options);
const blob2 = Blob.fromStream(stream, options);
```

Points to consider:

- We could instead make this `stream.toBlob()`, but I feel the layering of keeping streams ignorant of blobs is a bit cleaner.
- We may not want to introduce this because it's better if people avoid using blobs? (Or is it just blob URLs that we dislike?)
- If someone wanted a `File`, we could either add `File.fromStream(stream, fileName, options)` or we could have people do `new File([Blob.fromStream(stream)], fileName, options)`. Probably `File.fromStream()` is nicer.

-- 
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/issues/140

Received on Friday, 30 August 2019 17:26:48 UTC