Socket
Book a DemoInstallSign in
Socket

stream-write

Package Overview
Dependencies
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

stream-write

Write to a stream callback style

Source
npmnpm
Version
1.0.1
Version published
Weekly downloads
233
28.73%
Maintainers
1
Weekly downloads
 
Created
Source

stream-write

Write to streams, respecting backpressure.

build status

Example

Write random numbers to an http response until it ends:

var write = require('stream-write');
var http = require('http');

http.createServer(function(req, res){
  (function next(){
    write(res, ''+Math.random(), function(err, open){
      if (err) throw err;
      if (open) next();
    });
  })();
}).listen(8000);

write(stream, chunk, fn)

Write chunk to stream and call fn once stream is writable again, or an error happened.

The second parameter to fn is false when stream ended and you should stop writing to it.

HTTP special casing

When an HTTP request ended, the HTTP response stays writable, only it's underlying socket closes. To stay consistent with other streams' behavior, in that case write() will throw an error itself.

Installation

$ npm install stream-write

License

MIT

FAQs

Package last updated on 26 Mar 2015

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts