Consider Blob.fromStream (returns a Promise<Blob>)
Nessuno ha ancora preso questa issue.
- Lingua principale
- HTML
- Stelle
- 118
- Fork
- 52
- Merge medio
- 9g 16h
- PR unite (30g)
- 1
Descrizione
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
const blob = await Blob.fromStream(stream);
There is a bigger savings if we add an options parameter:
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 addFile.fromStream(stream, fileName, options)or we could have people donew File([Blob.fromStream(stream)], fileName, options). ProbablyFile.fromStream()is nicer. - This does not allow creating a blob that represents an "in progress" stream, which I've heard people have wanted in order to have self-referential blobs. That would require new concepts and infrastructure. This proposal is basically just exposing existing infrastructure in a more straightforward way.
Guida per i contributori
Apri la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Direzione di ricerca
L’issue non indica file del repository né test. Inizia confrontando le API attuali di Blob, ReadableStream e Response(...).blob() descritte qui; per completare il lavoro sarebbe necessario un design dell’API definito per Blob.fromStream, per le relative opzioni e per la questione correlata a File, seguito dalle specifiche e dai test di conformità applicabili.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Valutazione
- Stack tecnologico
- html
- Ambito
- api, web-dev
- Tipo di issue
- Funzionalità
- Difficoltà
- 5/5
- Tempo stimato
- Più di una settimana
- Stato di attività
- Ferma
- Chiarezza
- Abbastanza chiara
- Idoneità per principianti
- 25/100