Socket
Socket
Sign inDemoInstall

level-ws

Package Overview
Dependencies
6
Maintainers
4
Versions
7
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    level-ws

A basic WriteStream implementation for LevelUP


Version published
Maintainers
4
Created

Changelog

Source

[2.0.0] - 2019-03-30

Changed

  • Upgrade readable-stream from ^2.2.8 to ^3.1.0 (#105) (@ralphtheninja)
  • Upgrade level devDependency from ^4.0.0 to ^5.0.1 (#109) (@vweevers)
  • Upgrade nyc devDependency from ^12.0.2 to ^13.2.0 (#108) (@vweevers)
  • Upgrade standard devDependency from ^11.0.1 to ^12.0.0 (#102) (@ralphtheninja)
  • Apply common project tweaks (#106, #107) (@vweevers)

Removed

Readme

Source

level-ws

A basic WriteStream implementation for levelup

level badge npm Node version Travis npm Coverage Status JavaScript Style Guide Backers on Open Collective Sponsors on Open Collective

level-ws provides the most basic general-case WriteStream for levelup. It was extracted from the core levelup at version 0.18.0.

level-ws is not a high-performance WriteStream. If your benchmarking shows that your particular usage pattern and data types do not perform well with this WriteStream then you should try one of the alternative WriteStreams available for levelup that are optimised for different use-cases.

If you are upgrading: please see UPGRADING.md.

Usage

var level = require('level')
var WriteStream = require('level-ws')

var db = level('/path/to/db')
var ws = WriteStream(db) // ...

API

ws = WriteStream(db[, options])

Creates a Writable stream which operates in objectMode, accepting objects with 'key' and 'value' pairs on its write() method.

The optional options argument may contain:

  • type (string, default: 'put'): Default batch operation for missing type property during ws.write().

The WriteStream will buffer writes and submit them as a batch() operations where writes occur within the same tick.

var ws = WriteStream(db)

ws.on('error', function (err) {
  console.log('Oh my!', err)
})
ws.on('close', function () {
  console.log('Stream closed')
})

ws.write({ key: 'name', value: 'Yuri Irsenovich Kim' })
ws.write({ key: 'dob', value: '16 February 1941' })
ws.write({ key: 'spouse', value: 'Kim Young-sook' })
ws.write({ key: 'occupation', value: 'Clown' })
ws.end()

The standard write(), end() and destroy() methods are implemented on the WriteStream. 'drain', 'error', 'close' and 'pipe' events are emitted.

You can specify encodings for individual entries by setting .keyEncoding and/or .valueEncoding:

writeStream.write({
  key: new Buffer([1, 2, 3]),
  value: { some: 'json' },
  keyEncoding: 'binary',
  valueEncoding : 'json'
})

If individual write() operations are performed with a 'type' property of 'del', they will be passed on as 'del' operations to the batch.

var ws = WriteStream(db)

ws.on('error', function (err) {
  console.log('Oh my!', err)
})
ws.on('close', function () {
  console.log('Stream closed')
})

ws.write({ type: 'del', key: 'name' })
ws.write({ type: 'del', key: 'dob' })
ws.write({ type: 'put', key: 'spouse' })
ws.write({ type: 'del', key: 'occupation' })
ws.end()

If the WriteStream is created with a 'type' option of 'del', all write() operations will be interpreted as 'del', unless explicitly specified as 'put'.

var ws = WriteStream(db, { type: 'del' })

ws.on('error', function (err) {
  console.log('Oh my!', err)
})
ws.on('close', function () {
  console.log('Stream closed')
})

ws.write({ key: 'name' })
ws.write({ key: 'dob' })
// but it can be overridden
ws.write({ type: 'put', key: 'spouse', value: 'Ri Sol-ju' })
ws.write({ key: 'occupation' })
ws.end()

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.

Donate

To sustain Level and its activities, become a backer or sponsor on Open Collective. Your logo or avatar will be displayed on our 28+ GitHub repositories, npm packages and (soon) our website. 💖

Backers

Open Collective backers

Sponsors

Open Collective sponsors

License

MIT © 2012-present Contributors.

Keywords

FAQs

Last updated on 30 Mar 2019

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc