# level-temp

> Create a temporary sublevel that is guaranteed to be empty

Latest version **2.1.0** (published 2015-02-03) · MIT license · 0 weekly downloads

## Install

```sh
npm install level-temp
pnpm add level-temp
yarn add level-temp
bun add level-temp
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 2.1.0 |
| Published | 2015-02-03 |
| First published | 2015-01-28 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 3 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 10 |
| Author | Mathias Buus |
| Maintainers | mafintosh |

## Links

- npm: https://www.npmjs.com/package/level-temp
- Repository: https://github.com/mafintosh/level-temp
- Issues: https://github.com/mafintosh/level-temp/issues
- npm.io page: https://npm.io/package/level-temp

## Dependencies (3)

- [xtend](https://npm.io/package/xtend.md) ^4.0.0
- [levelup](https://npm.io/package/levelup.md) ^0.19.0
- [subleveldown](https://npm.io/package/subleveldown.md) ^2.0.0

## Recent versions

- 2.1.0 (latest) — 2015-02-03
- 2.0.0 — 2015-02-03
- 1.0.2 — 2015-01-29
- 1.0.1 — 2015-01-28
- 1.0.0 — 2015-01-28

## README

# level-temp

Create a temporary sublevel that is guaranteed to be empty.

```
npm install level-temp
```

[![build status](http://img.shields.io/travis/mafintosh/level-temp.svg?style=flat)](http://travis-ci.org/mafintosh/level-temp)

## Usage

``` js
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.

``` js
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](https://gihub.com/rvagg/node-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

---
_Source: https://npm.io/package/level-temp · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
