Socket
Socket
Sign inDemoInstall

level-ws

Package Overview
Dependencies
9
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
Weekly downloads
157K
decreased by-11.07%
Maintainers
4
Install size
215 kB
Created
Weekly downloads
 

Changelog

Source

[1.0.0] - 2018-06-30

Changed

  • Refactor test options to always set createIfMissing and errorIfExists (@ralphtheninja)
  • Move setUp() function into test() (@ralphtheninja)
  • Move openTestDatabase() calls into test() and pass ctx to tests (@ralphtheninja)
  • Test error after db.close() and after cleanup() (@ralphtheninja)
  • Use after in cleanup() (@ralphtheninja)
  • Use only readable-stream from user land (@ralphtheninja)
  • Use ^ for devDependencies (@ralphtheninja)
  • Switch to plain MIT license (@ralphtheninja)
  • Replace util.inherits with inherits module (@ralphtheninja)
  • Replace this._destroyed with this.destroyed from Writable (@ralphtheninja)
  • Export single function that creates the stream (@ralphtheninja)
  • Flip parameters in WriteStream constructor (@ralphtheninja)
  • Verify results once using level-concat-iterator intead of multiple db.get() operations (@ralphtheninja)
  • Update README style (@ralphtheninja)
  • Optimize internal batch _buffer by pushing transformed data (@ralphtheninja)
  • Use tempy for test locations and remove cleanup() (@vweevers)
  • Pass complete object in _write() extending default type (@ralphtheninja)
  • Link to node 8 lts version of Writable (@ralphtheninja)
  • Support custom highWaterMark (@vweevers)
  • Change maxBufferLength to pause rather than drop writes (@vweevers)

Added

Removed

Fixed

Readme

Source

level-ws

A basic WriteStream implementation for levelup

level badge npm Node version Build Status dependencies npm Coverage Status JavaScript Style Guide

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()

License

MIT © 2012-present level-ws Contributors.

Keywords

FAQs

Last updated on 30 Jun 2018

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