0.1.4 • Published 10 years ago

duplex-transform v0.1.4

Weekly downloads
2
License
MIT
Repository
github
Last release
10 years ago

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)