Consider Blob.fromStream (returns a Promise<Blob>)
Dieses Issue hat noch niemand übernommen.
- Vorherrschende Sprache
- HTML
- Sterne
- 118
- Forks
- 52
- Ø Merge
- 9 T. 16 Std.
- Gemergte PRs (30 T.)
- 1
Beschreibung
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.
Beitragsleitfaden
Erste Schritte
- Lies das ganze Issue und danach den Beitragsleitfaden des Projekts.
- Schreib ins Issue, dass du es übernimmst — das erspart doppelte Arbeit.
- Forke das Repository und arbeite in einem Branch.
- Öffne einen Pull Request, der die Issue-Nummer nennt.
Rechercherichtung
Das Issue nennt keine Repository-Dateien oder Tests. Beginne damit, die hier beschriebenen aktuellen APIs von Blob, ReadableStream und Response(...).blob() zu vergleichen; für den Abschluss wären ein festgelegtes API-Design für Blob.fromStream, seine Optionen und die damit verbundene File-Frage erforderlich, gefolgt von den anwendbaren Spezifikations- und Konformitätstests.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Bewertung
- Tech-Stack
- html
- Bereich
- api, web-dev
- Issue-Typ
- Feature
- Schwierigkeit
- 5/5
- Geschätzter Aufwand
- Über eine Woche
- Aktivitätsstatus
- Veraltet
- Klarheit
- Größtenteils klar
- Anfängerfreundlichkeit
- 25/100