json-multibuffer-stream
v3.0.0
Published
Transform stream that encodes JSON data as multibuffers
Downloads
18
Readme
json-multibuffer-stream
Transform stream that encodes JSON data as multibuffers.
usage
var jsonBuffStream = require('json-multibuffer-stream')
var jsonEncoder = jsonBuffStream()
fs.createReadStream('newline-delimited.json').pipe(jsonEncoder).pipe(httpPostToSomeServer)
optional arguments: jsonBuffStream(headers, onRow)
var encoder = jsonBuffStream(onRow)
function onRow(json) {
// gets called on every row with the json data right before it gets encoded
}
you can also pass in a custom headers array to control how the resulting multibuffer is encoded
var headers = ['z', 'x', 'y']
var encoder = jsonBuffStream(headers)
encoder.write({x: 1, y: 2, z: 3})
// multibuffer will be something like [3,2,1]
you can write either JSON strings or JavaScript objects to the stream. JSON strings will get JSON.parse()'d
use a multibuffer-stream .unpackStream()
to decode the data on the other end