stream: Add option to `Readable.take` operator to not close the stream
Nadie ha tomado este issue todavía.
- Lenguaje dominante
- JavaScript
- Estrellas
- 122k
- Forks
- 37.3k
- Merge medio
- 4 d 2 h
- PR fusionados (30 d)
- 283
Descripción
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();
Guía de contribución
Primeros pasos
- Lee el issue completo y luego la guía de contribución del proyecto.
- Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
- Haz un fork del repositorio y trabaja en una rama.
- Abre un pull request que haga referencia al número del issue.
Línea de trabajo
Comienza con el operador Readable.take y compara su comportamiento actual de cierre del stream con la alternativa mencionada async iterator({ destroyOnReturn: false }). Revisa la discusión circundante sobre la API de streams y define la finalización como la compatibilidad con la opción closeStream propuesta, preservando el comportamiento predeterminado existente.
Escrito por el modelo de indexación a partir del texto del issue.
Evaluación
- Stack tecnológico
- javascript, node.js
- Área
- api, backend
- Tipo de issue
- Nueva funcionalidad
- Dificultad
- 4/5
- Tiempo estimado
- 3-5 días
- Estado de actividad
- Tranquilo
- Claridad
- Bastante claro
- Aptitud para principiantes
- 45/100