sizedown

A LevelDOWN that monitors and optionally limits it's on-disk size.

Usage no npm install needed!

<script type="module">
  import sizedown from 'https://cdn.skypack.dev/sizedown';
</script>

README

sizedown

A LevelDOWN that monitors and optionally limits the on-disk size.

Travis

npm install sizedown

db = sizedown([leveldown], [bytes])

Example

Monitor the size and see the current size in bytes with db.db.getSize:

var sizedown = require('sizedown')

function down (loc) {
  return sizedown(leveldown(loc), 0)
}

var db = levelup('test', {db: down)})

db.put('akey', 'a value', function (err) {
  db.db.getSize(function (err, size) {
    // approximateSize of the whole thing
  })
})
// limit is number of bytes to allow via put and batch before erroring
return sizedown(leveldown(loc), {limit: 1})

var db = levelup('hello', down(1))

db.on('ready', function () {
  db.put('akey', 'a value', function (err) {
    // err.message = 'Exceeds limit of 1 byte'
    db.get('akey', function (err, value) {
      // err.notFound === true
    })
  })
})