# smalltable

> An on-disk key-value store with very few features

Latest version **1.0.1** (published 2016-01-24) · MIT license · 0 weekly downloads

## Install

```sh
npm install smalltable
pnpm add smalltable
yarn add smalltable
bun add smalltable
```

## 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 | 1.0.1 |
| Published | 2016-01-24 |
| First published | 2016-01-24 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 4 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 30 |
| Author | Mathias Buus |
| Maintainers | mafintosh |

## Links

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

## Dependencies (4)

- [thunky](https://npm.io/package/thunky.md) ^0.1.0
- [buffer-equals](https://npm.io/package/buffer-equals.md) ^1.0.3
- [readable-stream](https://npm.io/package/readable-stream.md) ^2.0.5
- [random-access-open](https://npm.io/package/random-access-open.md) ^1.1.0

## Recent versions

- 1.0.1 (latest) — 2016-01-24
- 1.0.0 — 2016-01-24

## README

# smalltable

An on-disk key-value store with very few features

```
npm install smalltable
```

## Usage

``` js
var smalltable = require('smalltable')
var db = smalltable('my.db', {
  hash: 'sha1', // use sha1 to hash the keys
  valueLength: 5 // values take up 5 bytes
})

db.put('hello', 'world', function (err) {
  if (err) throw err
  db.get('hello', function (err, value) {
    if (err) throw err
    console.log('hello -> ' + value)
  })
})
```

## API

#### `db = smalltable(filename, options)`

Create a new db instance. The data will stored in a file called `filename`.

Options include:

``` js
{
  hash: 'sha1',    // optional key hashing algorithm
  keyLength: 5,    // optional key byte length
  valueLength: 5,  // value byte length
  values: 128,     // optional inital value count
  truncate: false  // optional truncate the database
}
```

If you don't specify `hash` you have to specify `keyLength`. If you store more than `values` values the database will be automatically expanded to contain more values. Currently this requires re-indexing all values stored in the database.

#### `db.put(key, value, [cb])`

Store a value. If the value if less than `valueLength` it will be zero-padded.

#### `db.get(key, cb)`

Retrive a value. Callback is called with `cb(err, buffer)`. If the key isn't found an error is returned.

#### `db.del(key, [cb])`

Delete a value

#### `db.flush(cb)`

Flushes the database by performing an fsync on the underlying file descriptor

#### `db.close(cb)`

Closes the underlying file descriptor.

#### `stream = db.list()`

Get a stream of all values `{key: key, value: value}` in the database. If `hash` was set in the constructor the key will be the hash of the key.

## License

MIT

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