Skip to content
This repository was archived by the owner on Feb 7, 2021. It is now read-only.

Latest commit

 

History

History
48 lines (36 loc) · 704 Bytes

README.md

File metadata and controls

48 lines (36 loc) · 704 Bytes

pipelining

Xhr chunked stream client for the browser and node.js

Install

$ npm install pipelining

Usage

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();
}