w3c / w3c/FileAPI

Consider Blob.fromStream (returns a Promise<Blob>)

オープン
#140 コメント 7 件 リアクション 0 件 担当者 0 名 GitHub で見る

まだ誰も着手していません。

feature request TPAC2024
主要言語
HTML
スター
118
フォーク
52
平均マージ
9日 16時間
マージ済み PR(30日)
1

説明

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 add File.fromStream(stream, fileName, options) or we could have people do new File([Blob.fromStream(stream)], fileName, options). Probably File.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.

コントリビューションガイド

コントリビューションガイドを開く

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

調査の方向性

この issue ではリポジトリのファイルもテストも指定されていません。まず、ここで説明されている現在の Blob、ReadableStream、Response(...).blob() API を比較します。完了には、Blob.fromStream、そのオプション、および関連する File の問題について API 設計を確定し、その後に該当する仕様と適合性テストを整備する必要があります。

索引モデルが issue の本文から書いたものです。

評価

技術スタック
html
領域
api, web-dev
issue の種類
機能追加
難易度
5/5
見積もり時間
1週間以上
活発さ
停滞
明瞭さ
おおむね明確
初心者へのやさしさ
25/100

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。