# to2

> A write stream constructor that supports a flush function that is called before `finish` is emitted

Latest version **1.0.0** (published 2016-06-05) · MIT license · 0 weekly downloads

## Install

```sh
npm install to2
pnpm add to2
yarn add to2
bun add to2
```

## 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 | 2016-06-05 |
| First published | 2016-06-05 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 1 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | mafintosh |
| Maintainers | substack |
| Keywords | writable, stream |

## Links

- npm: https://www.npmjs.com/package/to2
- Repository: https://github.com/substack/to2
- Homepage: https://github.com/substack/to2#readme
- Issues: https://github.com/substack/to2/issues
- npm.io page: https://npm.io/package/to2

## Dependencies (1)

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

## Alternatives

- [byte-size](https://npm.io/package/byte-size.md) — 2.1M weekly downloads
- [speed-limiter](https://npm.io/package/speed-limiter.md) — 16.0K weekly downloads
- [@powersync/node](https://npm.io/package/@powersync/node.md) — 10.9K weekly downloads
- [@ledgerhq/coin-cardano](https://npm.io/package/@ledgerhq/coin-cardano.md) — 1.0K weekly downloads
- [@jayesol/jayeson.lib.streamfinder](https://npm.io/package/@jayesol/jayeson.lib.streamfinder.md) — 1.0K weekly downloads

## Recent versions

- 1.0.0 (latest) — 2016-06-05

## README

# to2

A write stream constructor that supports a flush function that is called before `finish` is emitted

```
npm install to2
```

This module is an alias of [flush-write-stream][1] for better symmetry with
[from2][2].

[![build status](http://img.shields.io/travis/mafintosh/flush-write-stream.svg?style=flat)](http://travis-ci.org/mafintosh/flush-write-stream)

[1]: https://npmjs.com/package/flush-write-stream
[2]: https://npmjs.com/package/from2

## Usage

``` js
var writer = require('to2')

var ws = writer(write, flush)

ws.on('finish', function () {
  console.log('finished')
})

ws.write('hello')
ws.write('world')
ws.end()

function write (data, enc, cb) {
  // i am your normal ._write method
  console.log('writing', data.toString())
  cb()
}

function flush (cb) {
  // i am called before finish is emitted
  setTimeout(cb, 1000) // wait 1 sec
}
```

If you run the above it will produce the following output

```
writing hello
writing world
(nothing happens for 1 sec)
finished
```

## API

#### `var ws = writer([options], write, [flush])`

Create a new writable stream. Options are forwarded to the stream constructor.

#### `var ws = writer.obj([options], write, [flush])`

Same as the above except `objectMode` is set to `true` per default.

## License

MIT

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