Skip to content

schmidt-sebastian/node-duplex-transform

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

12 Commits
 
 
 
 
 
 
 
 

Repository files navigation

duplex-transform

Streams2 syntactic sugar for making wrapping + piping duplex streams with transforms (like encoding/decoding).

npm install duplex-transform

dat

Use Case

Say you have a duplex stream, and it's super cool. Except that it speaks some protocol you don't particularly like, so you want to transform it to something else. It's a bit annoying to have to make three streams and pipe them every time. This tiny module makes this a tiny bit nicer.

This module uses + plays well with through2 and common transform stream patterns.

Example

var dgramStream = require('dgram-stream')
var duplexTransform = require('duplex-transform')

var ugly = dgramStream('udp4')
ugly.bind(1234)

function encode(data, enc, next) {
  this.push({
    to: { port: 1234 }, // talking to ourselves :S
    payload: data,
  })
  next()
}

function decode(data, enc, next) {
  this.push(data.payload)
  next()
}

var fancy = duplexTransform.obj(encode, ugly, decode)
process.stdin.pipe(fancy).pipe(process.stdout)

About

duplex transform streams

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • JavaScript 100.0%