Xhr chunked stream client for the browser and node.js
$ npm install pipelining
Client (browser or node.js)
const pipelining = require('pipelining');
const reader = pipelining('/test');
function handle(data) {
console.log(data);
}
function read() {
reader.read().then(partial => {
if (partial.done) {
return;
}
handle(partial.data).then(read);
});
}
read()
Server
const pipelining = require('pipelining');
// http handler
function (req, res) {
res.write(pipelining.pack(1));
// after several seconds..
res.write(pipelining.pack({ tom: 'test' }));
// after 1 min..
res.end();
}