Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

239
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!