Skip to content

Instantly share code, notes, and snippets.

@bowin
Last active November 15, 2022 00:02
Show Gist options
  • Save bowin/e18dd9afdbac597507d92b489fb0f4f7 to your computer and use it in GitHub Desktop.
Save bowin/e18dd9afdbac597507d92b489fb0f4f7 to your computer and use it in GitHub Desktop.
Node.js Stream PassThrough Usage
const {PassThrough} = require('stream')
const fs = require('fs')

const d = new PassThrough()  

fs.createReadStream('tt2.js').pipe(d)  // can be piped from reaable stream

d.pipe(process.stdout)                 // can pipe to writable stream 
d.on('data', console.log)              // also like readable
@sebasalvarado
Copy link

Thanks very helpful!

@miriame
Copy link

miriame commented Aug 7, 2018

thanks

@rajathgunners
Copy link

thanks

@Denys-Bushulyak
Copy link

thnx.

@Mr-Ahmadi
Copy link

const buffer = Buffer.from(
    await blob.arrayBuffer()
)
const readableBuffer = new PassThrough()
readableBuffer.on('error', err => {
    console.log(err)
})
readableBuffer.write(buffer)
readableBuffer.end()
readableBuffer.destroy()

are all the errors handled in this code?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment