Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

237
Vistas
Turning two streams into a single stream to pipe with read and write streams

I want to pipe two streams - both Transform streams.

Stream 1 (line2Arr) - turns a line into an array inside an object and sends it back down the stream

Stream 2 (arr2Json) - takes the object with the array, creates a different object with the info and send it back down the stream.

All of this i want to wrap up in one stream (line2JsonStream) so that I can then do for example:

pipeline(readStream, line2JsonStream, writeStream)

What does line2JsonStream class need to be in order to be able to do that? Does it need to extend Transform? and if so what would it return exactly?

When I use them seperately pipeline(readStream, line2Arr, arr2Json, writeStream) they work, but I want to be able to use it as a single stream, and anything i've done so far didn't work.

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

When implementing line2Arr and arr2Json as instances of a Transfom like this

const line2Arr = new Transform({
  transform( chunk, enc, cb ) {
    const transformed = doSomeTransformMagic( chunk );
    cb( null, transformed );
  }
});

you could do

readStream.pipe( line2Arr ).pipe( arr2Json ).pipe( writeStream )

If I understand your question correctly, you want to squash the two Transform instances into a single Stream so that you might do

readStream.pipe( line2ArrAndArr2Json ).pipe( writeStream )

which I think is not easily possible by using the two created Transform instances line2Arr and arr2Json. The pipe() function requires a Writable as an argument and returns the same object. In our case, that is a Transform wich also implements Readable and its pipe() function. To make the above code work, you'd need to pass the Writable interface of line2Arr to readStream.pipe() but return the Readable interface of arr2Json from readStream.pipe(), which I don't think is possible.

about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda