Skip to content
This repository has been archived by the owner on Nov 25, 2020. It is now read-only.
/ wrap-json-stream Public archive

wrap a duplex stream with JSONStream parse and stringify

License

Notifications You must be signed in to change notification settings

vweevers/wrap-json-stream

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

wrap-json-stream

Wrap a duplex stream with JSONStream parse and stringify.

npm status Dependency status

example

const json = require('wrap-json-stream')
    , through2 = require('through2')

const wrapped = json(through2.obj(function(obj, _, next){
  obj.y = obj.x*2
  next(null, obj)
}))

wrapped.on('data', (data) => console.log(data.toString()))
wrapped.write('{"x":1}\n{"x":2}')
{"x":1,"y":2}

{"x":2,"y":4}

json(stream(s), [opts])

Options:

  • fwd: array of events to forward from the inner stream to the outer
  • inherit: array of properties to inherit
const inner = someStream()
inner.name = 'my-stream'

const outer = json(inner, { inherit: ['name'], fwd: ['sync'] })

outer.on('sync', () => console.log(outer.name))
inner.emit('sync')

install

With npm do:

npm install wrap-json-stream

license

MIT © Vincent Weevers

About

wrap a duplex stream with JSONStream parse and stringify

Resources

License

Stars

Watchers

Forks

Packages

No packages published