Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

level-ws

Level1.2mMIT4.0.0

A basic writable stream for abstract-level databases

level, leveldb, stream, levelup

readme

level-ws

A basic writable stream for 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.

level badge npm Node version Test Coverage Standard Common Changelog Donate

Usage

If you are upgrading: please see UPGRADING.md.

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 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 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 for more details.

License

MIT

changelog

Changelog

4.0.0 - 2022-07-01

If you are upgrading: please see UPGRADING.md.

Changed

  • Breaking: bump readable-stream from 3 to 4 (082b8d6) (Vincent Weevers)
  • Breaking: use classes, requiring new (dafafb2) (Vincent Weevers)
  • Breaking: drop Node.js 10 (817c30c) (Vincent Weevers)

Fixed

  • Cleanup README and add missing docs for options (94a2a8e) (Vincent Weevers).

3.0.0 - 2021-04-25

If you are upgrading: please see UPGRADING.md.

Changed

2.0.0 - 2019-03-30

Changed

Removed

1.0.0 - 2018-06-30

Changed

Added

Removed

Fixed

  • Fix erroneous test on missing type (@ralphtheninja)
  • Fix race condition by flushing before finish (@vweevers)
  • Fix _destroy to emit 'close' after error (@vweevers)

0.1.0 - 2017-04-07

Changed

  • Upgrade readable-stream from ~2.0.6 to ^2.2.8 (@mcollina)
  • Upgrade xtend from ~2.2.1 to ^4.0.0 (@mcollina)

0.0.1 - 2016-03-14

Changed

Added

0.0.0 - 2013-10-12

:seedling: Initial release.