# koa-write

> Write to koa bodies in generator style

Latest version **0.0.2** (published 2014-04-14) · MIT license · 0 weekly downloads

## Install

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

## Health

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

Positive: no vulnerabilities.

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

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.0.2 |
| Published | 2014-04-14 |
| First published | 2014-04-10 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 1 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 6 |
| Maintainers | juliangruber |

## Links

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

## Dependencies (1)

- [co-write](https://npm.io/package/co-write.md) ~0.3.0

## Recent versions

- 0.0.2 (latest) — 2014-04-14
- 0.0.1 — 2014-04-14
- 0.0.0 — 2014-04-10

## README

# koa-write

  Write to koa bodies in generator style, respecting back pressure and
  throwing on closed sockets.

## Example

```js
var koa = require('koa');
var co = require('co');
var write = require('koa-write');
var PassThrough = require('stream').PassThrough;
var wait = require('co-wait');

var app = koa();
app.use(function(){
  var ctx = this;
  ctx.body = PassThrough();

  co(function*(){
    for (var i = 0; i < 100; i++) {
      yield write(ctx, Date.now().toString());
    }
  }, this.onerror);
});
```

## API

### write(ctx, chunk)

  Write `chunk` to `ctx`.
  
  Yields as soon as you're good to write more.

  Throws when the socket is already closed, so it doesn't make sense to write
  more.

## Why not just co-write?

  [co-write](https://github.com/juliangruber/co-write) writes to streams and
  does the same http socket handling, however it expects to be passed an http
  response object for that to work. In the situation where you have
  `stream.pipe(res)` you'll want to write to `stream`, however end when
  `res.socket` ends.

## Installation

```bash
$ npm install koa-write
```

## License

  MIT

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