项目作者: Level

项目描述 :
A basic WriteStream implementation for levelup.
高级语言: JavaScript
项目地址: git://github.com/Level/level-ws.git
创建时间: 2013-10-12T09:08:34Z
项目社区:https://github.com/Level/level-ws

开源协议:MIT License

下载


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.

  1. const { Level } = require('level')
  2. const WriteStream = require('level-ws')
  3. const db = new Level('./db', { valueEncoding: 'json' })
  4. const ws = new WriteStream(db)
  5. ws.on('close', function () {
  6. console.log('Done!')
  7. })
  8. ws.write({ key: 'alice', value: 42 })
  9. ws.write({ key: 'bob', value: 7 })
  10. // To delete entries, specify an explicit type
  11. ws.write({ type: 'del', key: 'tomas' })
  12. ws.write({ type: 'put', key: 'sara', value: 16 })
  13. 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