Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

234
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda