nodejs / nodejs/node

stream: Add option to `Readable.take` operator to not close the stream

オープン
#46,980 コメント 42 件 リアクション 0 件 担当者 0 名 GitHub で見る

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

feature request stream
主要言語
JavaScript
スター
122k
フォーク
37.3k
平均マージ
4日 2時間
マージ済み PR(30日)
283

説明

What is the problem this feature will solve?

I will be able to do this:

const csvParsedStream = fs
	.createReadStream('file.csv')
	.compose(csvParse({ columns: false }));

const [columns] = await csvParsedStream
	.take(1)
	.toArray();

// This will now be empty and no data as take already consumed the stream
const parsed = await csvParsedStream
   .map((row) => parseRowByColumns(row, columns))
   .toArray();

Another example (I know I can use [first, ...rest] this is just an example):

const a = Readable.from([1, 2, 3, 4, 5, 6, 7, 8, 9, 10]);
const [first] = await a.take(1).toArray();

console.log(first);
// [1]

const rest = await a.toArray();
console.log(rest)
// []
What is the feature you are proposing to solve the problem?

Adding closeStream option to the take operator that with default value true that I could disable closing the stream

const csvParsedStream = fs
	.createReadStream('file.csv')
	.compose(csvParse({ columns: false }));

const [columns] = await csvParsedStream
	.take(1, { closeStream: false })  // Right now this would close the stream, but we give it an option to not
	.toArray();

const parsed = await csvParsedStream.map((row) => parseRowByColumns(row, columns)).toArray();
What alternatives have you considered?

Get the first value from stream as async itarator and rest

let columns;
for await (const c of csvParsedStream.iterator<string[]>({ destroyOnReturn: false })) {
	columns = c;

	break;
}

const parsed = await csvParsedStream
    .map((row) => parseRowByColumns(row, columns))
    .toArray();

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

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

はじめの一歩

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

調査の方向性

Readable.take オペレーターから始め、現在のストリーム終了動作を、言及されている async iterator({ destroyOnReturn: false }) の代替案と比較してください。ストリーム API に関する周辺の議論を確認し、既存のデフォルト動作を維持しながら、提案された closeStream オプションをサポートすることを完了の定義としてください。

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

評価

技術スタック
javascript, node.js
領域
api, backend
issue の種類
機能追加
難易度
4/5
見積もり時間
3〜5日
活発さ
静か
明瞭さ
おおむね明確
初心者へのやさしさ
45/100

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

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