duplex-transform

0.1.4 • Public • Published

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)

/duplex-transform/

    Package Sidebar

    Install

    npm i duplex-transform

    Weekly Downloads

    8

    Version

    0.1.4

    License

    MIT

    Last publish

    Collaborators

    • jbenet