Socket
Socket
Sign inDemoInstall

subleveldown

Package Overview
Dependencies
Maintainers
1
Versions
23
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

subleveldown - npm Package Compare versions

Comparing version 1.0.1 to 1.0.2

.travis.yml

5

example.js
var sub = require('./')
var memdb = require('memdb')
var levelup = require('levelup')
var memdown = require('memdown')
var db = memdb()
var db = levelup('test', {db:memdown})

@@ -6,0 +7,0 @@ var test = sub(db, 'test', {valueEncoding:'utf-8'})

6

package.json
{
"name": "subleveldown",
"version": "1.0.1",
"version": "1.0.2",
"description": "sublevels implemented using leveldowns",

@@ -12,3 +12,3 @@ "main": "index.js",

"devDependencies": {
"memdb": "^0.2.0"
"memdown": "^1.0.0"
},

@@ -29,4 +29,4 @@ "repository": {

"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
"test": "node test"
}
}

@@ -9,2 +9,4 @@ # subleveldown

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

@@ -30,4 +32,11 @@

## API
#### `subdb = sub(db, [prefix], [options])`
Returns a levelup instance that uses the subleveldown with `prefix`.
The `options` argument is passed to the [levelup](https://github.com/rvagg/node-levelup) constructor
## License
MIT

@@ -5,2 +5,8 @@ var util = require('util')

var concat = function(prefix, key) {
if (typeof key === 'string' && key.length) return prefix+key
if (Buffer.isBuffer(key) && key.length) return Buffer.concat([new Buffer(prefix), key])
return key
}
var SubIterator = function(ite, prefix) {

@@ -40,6 +46,6 @@ this.iterator = ite

gt: function(x) {
return self.prefix+(x || '')
return concat(self.prefix, (x || ''))
},
lt: function(x) {
return self.prefix+(x || '\xff')
return concat(self.prefix, (x || '\xff'))
}

@@ -78,15 +84,17 @@ }

SubDown.prototype.put = function(key, value, opts, cb) {
this.leveldown.put(this.prefix+key, value, opts, cb)
this.leveldown.put(concat(this.prefix, key), value, opts, cb)
}
SubDown.prototype.get = function(key, opts, cb) {
this.leveldown.get(this.prefix+key, opts, cb)
this.leveldown.get(concat(this.prefix, key), opts, cb)
}
SubDown.prototype.del = function(key, opts, cb) {
this.leveldown.del(this.prefix+key, opts, cb)
this.leveldown.del(concat(this.prefix, key), opts, cb)
}
SubDown.prototype.batch = SubDown.prototype._batch = function(operations, opts, cb) {
SubDown.prototype.batch =
SubDown.prototype._batch = function(operations, opts, cb) {
if (arguments.length === 0) return new abstract.AbstractChainedBatch(this)
if (!Array.isArray(operations)) return this.leveldown.batch.apply(null, arguments)

@@ -96,6 +104,6 @@ var subops = new Array(operations.length)

var o = operations[i]
subops[i] = {type:o.type, key:this.prefix+o.key, value:o.value}
subops[i] = {type:o.type, key:concat(this.prefix, o.key), value:o.value}
}
this.leveldown.batch(operations, opts, cb)
this.leveldown.batch(subops, opts, cb)
}

@@ -131,7 +139,13 @@

xopts.valueAsBuffer = opts.valueAsBuffer
return opts
xopts.reverse = opts.reverse
return xopts
}
var fixRange = function(opts) {
return (!opts.reverse || (!opts.end && !opts.start)) ? opts : {start:opts.end, end:opts.start}
}
SubDown.prototype.iterator = function(opts) {
var xopts = extend(wrap(opts, this._wrap), opts)
if (!opts) opts = {}
var xopts = extend(wrap(fixRange(opts), this._wrap), opts)
return new SubIterator(this.leveldown.iterator(xopts), this.prefix)

@@ -138,0 +152,0 @@ }

var test = require('tape')
var memdb = require('memdb')
var memdown = require('memdown')
var subdown = require('../subdown')
var levelup = require('levelup')
var testCommon = require('./common')

@@ -8,3 +9,3 @@ var testBuffer = new Buffer('this-is-test-data')

var down = function(loc) {
return subdown(memdb(loc), 'test')
return subdown(levelup(loc, {db:memdown}), 'test')
}

@@ -11,0 +12,0 @@

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc