stream: Add option to `Readable.take` operator to not close the stream
Chưa có ai nhận issue này.
- Ngôn ngữ chính
- JavaScript
- Star
- 122k
- Fork
- 37.4k
- Merge trung bình
- 4 ngày 3 giờ
- Pull request đã merge (30 ngày)
- 272
Mô tả
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();
Hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Hướng nghiên cứu
Bắt đầu từ toán tử Readable.take và so sánh hành vi đóng stream hiện tại của nó với phương án thay thế async iterator({ destroyOnReturn: false }) được đề cập. Xem lại phần thảo luận liên quan về stream API và xác định việc hoàn thành là hỗ trợ tùy chọn closeStream được đề xuất trong khi vẫn giữ nguyên hành vi mặc định hiện có.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Đánh giá
- Công nghệ
- javascript, node.js
- Lĩnh vực
- api, backend
- Loại issue
- Tính năng
- Độ khó
- 4/5
- Thời gian dự kiến
- 3-5 ngày
- Mức độ hoạt động
- Ít trao đổi
- Độ rõ ràng
- Khá rõ ràng
- Mức phù hợp với người mới
- 45/100