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.
📌 To instead write data using Web Streams, see
level-web-stream
.
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()
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, defaultInfinity
): limit the size of batches. When exceeded, the stream will stop processing writes until the current batch has been committed.highWaterMark
(number, default16
): buffer level whenstream.write()
starts returning false.
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.