node-json-stream-wrapper
A stream wrapper which wraps a stream into a JSON object
![Build Status](https://travis-ci.org/all3dp/node-json-stream-wrapper.svg)
Example Usage
import jsonStreamWrapper, {Base64Stream} from 'json-stream-wrapper';
import {createReadStream} from 'fs';
import {post} from 'request';
createReadStream('<example-file>')
.pipe(new Base64Stream())
.pipe(jsonStreamWrapper({example: 1}, 'file'))
.pipe(post({
url: 'http://target',
json: true
}));
or:
import jsonStreamWrapper, {Base64Stream} from 'json-stream-wrapper';
import {createReadStream} from 'fs';
let fstream = createReadStream('<example-file>');
const foo = fstream
.pipe(new Base64Stream())
.pipe(jsonStreamWrapper({example: 1}, 'file'));
streamToObject(foo, (obj) => {
console.log(obj);
});
function streamToObject(stream, cb) {
const chunks = [];
stream.on('data', (chunk) => {
chunks.push(chunk);
});
stream.on('end', () => {
cb(JSON.parse(chunks.join('')));
});
}