# stream-write

> Write to a stream promise style

Latest version **3.0.0** (published 2023-03-04) · MIT license · 0 weekly downloads

## Install

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

## Health

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

Positive: has types package; esm support; no vulnerabilities; high quality score.

Warnings: low downloads.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 3.0.0 |
| Published | 2023-03-04 |
| First published | 2015-03-26 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | separate (@types/stream-write) |
| Module format | ESM |
| Dependencies | 0 |
| Unpacked size | 3.8 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 8 |
| Maintainers | juliangruber |

## Links

- npm: https://www.npmjs.com/package/stream-write
- Repository: https://github.com/juliangruber/stream-write
- Homepage: https://github.com/juliangruber/stream-write#readme
- Issues: https://github.com/juliangruber/stream-write/issues
- npm.io page: https://npm.io/package/stream-write

## Recent versions

- 3.0.0 (latest) — 2023-03-04
- 2.0.0 — 2021-10-22
- 1.0.1 — 2015-03-26
- 1.0.0 — 2015-03-26

## README

# stream-write

  Write to streams, respecting backpressure.

## Example

  Write random numbers to an http response until it ends:

```js
import write from 'stream-write'
import http from 'node:http'

http.createServer((req, res) => {
  (async () => {
    while (true) {
      const isOpen = await write(res, String(Math.random()))
      if (!isOpen) break
    }
  })().catch(console.error)
}).listen(8000)
```

## write(stream, chunk)

  Write `chunk` to `stream` and returns a `Promise` that is resolved once `stream` is writable again, or rejects if an error happened.

  The promise's resolved value 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

```bash
$ npm install stream-write
```

## License

  MIT

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