Launch Week Day 1:Rust Support in Socket Is Now Generally Available.Learn More
Socket
Book a DemoInstallSign in
Socket

level-temp

Package Overview
Dependencies
Maintainers
1
Versions
5
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

level-temp

Create a temporary sublevel that is guaranteed to be empty

latest
Source
npmnpm
Version
2.1.0
Version published
Weekly downloads
7
600%
Maintainers
1
Weekly downloads
 
Created
Source

level-temp

Create a temporary sublevel that is guaranteed to be empty.

npm install level-temp

build status

Usage

var temp = require('level-temp')
var tmp = temp(db) // where db is a levelup

// call tmp to get a temporary sublevel that is empty

var a = tmp()

a.put('hello', 'world', function () {
  a.createReadStream()
    .on('data', function (data) {
      console.log('a has only one', data)
    })
})

// call tmp again to get another empty sublevel
var b = tmp()

b.put('hej', 'verden', function () {
  b.createReadStream()
    .on('data', function (data) {
      console.log('b has only one', data)
    })
})

If you explicitly close the tmp database (using tmpDb.close()) the contents will be removed. If you restart your application previous tmp data will be overriden as well.

API

tmp = temp(db, [options])

Create a new temporary sublevel generator. Options are used as default for any tmp databases created afterwards. Optionally you can set prefix to a string that will prefix all tmp sublevels created.

var tmp = temp(db, {valueEncoding: 'json'}) // set valueEncoding: json all tmp sublevels

var tmpDb = tmp([options])

Create a new temporary sublevel.

Any options passed here are forwarded to levelup with the default values from the temp constructor mixed in.

Per default an increasing number is used to prefix the temporary sublevels. To change this set the prefix to whatever string you want to use as a prefix.

The returned tmpDb is a regular levelup that will have its contents garbage collected when you call tmpDb.close() or at some point in the future when the temporary sublevel prefix is being reused.

License

MIT

FAQs

Package last updated on 03 Feb 2015

Did you know?

Socket

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