# co-write

> Write to streams, respecting backpressure

Latest version **1.0.0** (published 2015-03-26) · MIT license · 0 weekly downloads

## Install

```sh
npm install co-write
pnpm add co-write
yarn add co-write
bun add co-write
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.0 |
| Published | 2015-03-26 |
| First published | 2014-02-19 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 1 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 8 |
| Maintainers | juliangruber |

## Links

- npm: https://www.npmjs.com/package/co-write
- Repository: https://github.com/juliangruber/co-write
- Issues: https://github.com/juliangruber/co-write/issues
- npm.io page: https://npm.io/package/co-write

## Dependencies (1)

- [stream-write](https://npm.io/package/stream-write.md) ^1.0.0

## Recent versions

- 1.0.0 (latest) — 2015-03-26
- 0.3.1 — 2015-03-26
- 0.3.0 — 2014-02-20
- 0.2.0 — 2014-02-20
- 0.1.1 — 2014-02-20
- 0.1.0 — 2014-02-20
- 0.0.0 — 2014-02-19

## README

# co-write

  Write to streams, respecting backpressure.

  [![build status](https://secure.travis-ci.org/juliangruber/co-write.png)](http://travis-ci.org/juliangruber/co-write)

## Example

  Write random numbers to an http response until it ends:

```js
var write = require('co-write');
var co = require('co');
var http = require('http');

http.createServer(function(req, res){
  co(function*(){
    while (true) {
      var open = yield write(res, ''+Math.random());
      if (!open) return;
    }
  })();
}).listen(8000);
```

## yield write(stream, chunk)

  Write `chunk` to `stream` and block until `stream` is writable again.

  Returns false when `stream` ended and you should stop writing to it.

  Throws when `stream` already ended.

## 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

```bash
$ npm install co-write
```

## License

  MIT

---
_Source: https://npm.io/package/co-write · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
