# level-ws

> A basic writable stream for abstract-level databases

Latest version **4.0.0** (published 2022-07-01) · MIT license · 0 weekly downloads

## Install

```sh
npm install level-ws
pnpm add level-ws
yarn add level-ws
bun add level-ws
```

## 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 | 4.0.0 |
| Published | 2022-07-01 |
| First published | 2013-10-12 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Node | >=12 |
| Dependencies | 1 |
| Unpacked size | 16.6 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 22 |
| Maintainers | vweevers, rvagg, ralphtheninja |
| Keywords | level, leveldb, stream, levelup |

## Links

- npm: https://www.npmjs.com/package/level-ws
- Repository: https://github.com/Level/level-ws
- Issues: https://github.com/Level/level-ws/issues
- npm.io page: https://npm.io/package/level-ws

## Dependencies (1)

- [readable-stream](https://npm.io/package/readable-stream.md) ^4.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

- 4.0.0 (latest) — 2022-07-01
- 3.0.0 — 2021-04-25
- 2.0.0 — 2019-03-30
- 1.0.0 — 2018-06-30
- 0.1.0 — 2017-04-07
- 0.0.1 — 2016-03-15
- 0.0.0 — 2013-10-12

## README

# level-ws

**A basic writable stream for [`abstract-level`](https://github.com/Level/abstract-level) databases, using Node.js core streams.** This is not a high-performance stream. If benchmarking shows that your particular usage does not fit then try one of the alternative writable streams that are optimized for different use cases.

> :pushpin: To instead write data using Web Streams, see [`level-web-stream`](https://github.com/Level/web-stream).

[![level badge][level-badge]](https://github.com/Level/awesome)
[![npm](https://img.shields.io/npm/v/level-ws.svg)](https://www.npmjs.com/package/level-ws)
[![Node version](https://img.shields.io/node/v/level-ws.svg)](https://www.npmjs.com/package/level-ws)
[![Test](https://img.shields.io/github/workflow/status/Level/level-ws/Test?label=test)](https://github.com/Level/level-ws/actions/workflows/test.yml)
[![Coverage](https://img.shields.io/codecov/c/github/Level/level-ws?label=\&logo=codecov\&logoColor=fff)](https://codecov.io/gh/Level/level-ws)
[![Standard](https://img.shields.io/badge/standard-informational?logo=javascript\&logoColor=fff)](https://standardjs.com)
[![Common Changelog](https://common-changelog.org/badge.svg)](https://common-changelog.org)
[![Donate](https://img.shields.io/badge/donate-orange?logo=open-collective\&logoColor=fff)](https://opencollective.com/level)

## Usage

_If you are upgrading: please see [`UPGRADING.md`](UPGRADING.md)._

```js
const { Level } = require('level')
const WriteStream = require('level-ws')

const db = new Level('./db', { valueEncoding: 'json' })
const ws = new WriteStream(db)

ws.on('close', function () {
  console.log('Done!')
})

ws.write({ key: 'alice', value: 42 })
ws.write({ key: 'bob', value: 7 })

// To delete entries, specify an explicit type
ws.write({ type: 'del', key: 'tomas' })
ws.write({ type: 'put', key: 'sara', value: 16 })

ws.end()
```

## API

### `ws = new WriteStream(db[, options])`

Create a [writable stream](https://nodejs.org/dist/latest-v18.x/docs/api/stream.html#stream_class_stream_writable) that operates in object mode, accepting batch operations to be committed with `db.batch()` on each tick of the Node.js event loop. The optional `options` argument may contain:

- `type` (string, default: `'put'`): default batch operation type if not set on indididual operations.
- `maxBufferLength` (number, default `Infinity`): limit the size of batches. When exceeded, the stream will stop processing writes until the current batch has been committed.
- `highWaterMark` (number, default `16`): buffer level when `stream.write()` starts returning false.

## Contributing

[`Level/level-ws`](https://github.com/Level/level-ws) is an **OPEN Open Source Project**. This means that:

> Individuals making significant and valuable contributions are given commit-access to the project to contribute as they see fit. This project is more like an open wiki than a standard guarded open source project.

See the [Contribution Guide](https://github.com/Level/community/blob/master/CONTRIBUTING.md) for more details.

## License

[MIT](LICENSE)

[level-badge]: https://leveljs.org/img/badge.svg

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