Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

bdb

Package Overview
Dependencies
Maintainers
1
Versions
28
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

bdb - npm Package Compare versions

Comparing version 0.2.3 to 1.0.0

binding.gyp

11

lib/bdb.js

@@ -9,2 +9,3 @@ /**

const assert = require('bsert');
const DB = require('./db');

@@ -19,4 +20,12 @@ const Key = require('./key');

exports.create = (options) => {
const {memory, location} = options || {};
if (options == null)
options = {};
if (typeof options === 'string')
options = { location: options };
assert(options && typeof options === 'object');
const {memory, location} = options;
if (memory)

@@ -23,0 +32,0 @@ return new DB(MemDB, 'memory', options);

36

lib/db.js

@@ -56,10 +56,9 @@ /*!

const Backend = this.backend;
const db = new Backend(this.location);
// A lower-level binding.
if (db.binding && typeof db.binding.approximateSize === 'function') {
this.binding = db.binding;
if (Backend.leveldown) {
this.binding = new Backend(this.location);
this.leveldown = true;
} else {
this.binding = db;
this.binding = new Backend(this.location);
}

@@ -1267,6 +1266,2 @@ }

this.memory = false;
this.sync = false;
this.mapSize = 256 * (1024 << 20);
this.writeMap = false;
this.noSubdir = true;

@@ -1339,27 +1334,2 @@ if (options)

if (options.sync != null) {
assert(typeof options.sync === 'boolean',
'`sync` must be a boolean.');
this.sync = options.sync;
}
if (options.mapSize != null) {
assert(typeof options.mapSize === 'number',
'`mapSize` must be a number.');
assert(options.mapSize >= 0);
this.mapSize = options.mapSize;
}
if (options.writeMap != null) {
assert(typeof options.writeMap === 'boolean',
'`writeMap` must be a boolean.');
this.writeMap = options.writeMap;
}
if (options.noSubdir != null) {
assert(typeof options.noSubdir === 'boolean',
'`noSubdir` must be a boolean.');
this.noSubdir = options.noSubdir;
}
return this;

@@ -1366,0 +1336,0 @@ }

@@ -103,4 +103,3 @@ /**

size(v) {
assertType(Buffer.isBuffer(v));
return sizeString(v, null);
return sizeBuffer(v);
},

@@ -111,9 +110,8 @@ read(k, o) {

write(k, v, o) {
assertType(Buffer.isBuffer(v));
return writeString(k, v, o, null);
return writeBuffer(k, v, o);
}
},
hex: {
min: BUFFER_MIN,
max: BUFFER_MAX,
min: BUFFER_MIN.toString('hex'),
max: BUFFER_MAX.toString('hex'),
dynamic: true,

@@ -131,18 +129,18 @@ size(v) {

ascii: {
min: BUFFER_MIN,
max: BUFFER_MAX,
min: BUFFER_MIN.toString('binary'),
max: BUFFER_MAX.toString('binary'),
dynamic: true,
size(v) {
return sizeString(v, 'ascii');
return sizeString(v, 'binary');
},
read(k, o) {
return readString(k, o, 'ascii');
return readString(k, o, 'binary');
},
write(k, v, o) {
return writeString(k, v, o, 'ascii');
return writeString(k, v, o, 'binary');
}
},
utf8: {
min: BUFFER_MIN,
max: BUFFER_MAX,
min: BUFFER_MIN.toString('utf8'),
max: BUFFER_MAX.toString('utf8'),
dynamic: true,

@@ -168,60 +166,2 @@ size(v) {

assertLen(o + 20 <= k.length);
return k.toString('hex', o, o + 20);
},
write(k, v, o) {
assertType(writeHex(k, v, o) === 20);
return 20;
}
},
hash256: {
min: Buffer.alloc(32, 0x00),
max: Buffer.alloc(32, 0xff),
dynamic: false,
size(v) {
return 32;
},
read(k, o) {
assertLen(o + 32 <= k.length);
return k.toString('hex', o, o + 32);
},
write(k, v, o) {
assertType(writeHex(k, v, o) === 32);
return 32;
}
},
hash: {
min: Buffer.alloc(1, 0x00),
max: Buffer.alloc(64, 0xff),
dynamic: true,
size(v) {
return 1 + sizeHex(v);
},
read(k, o) {
assertLen(o + 1 <= k.length);
assertLen(k[o] >= 1 && k[o] <= 64);
assertLen(o + 1 + k[o] <= k.length);
return k.toString('hex', o + 1, o + 1 + k[o]);
},
write(k, v, o) {
const size = sizeHex(v);
assertType(size >= 1 && size <= 64);
assertLen(o + 1 <= k.length);
k[o] = size;
assertType(writeHex(k, v, o + 1) === size);
return 1 + size;
}
},
bhash160: {
min: Buffer.alloc(20, 0x00),
max: Buffer.alloc(20, 0xff),
dynamic: false,
size(v) {
return 20;
},
read(k, o) {
assertLen(o + 20 <= k.length);
return k.slice(o, o + 20);

@@ -235,3 +175,3 @@ },

},
bhash256: {
hash256: {
min: Buffer.alloc(32, 0x00),

@@ -253,3 +193,3 @@ max: Buffer.alloc(32, 0xff),

},
bhash: {
hash: {
min: Buffer.alloc(1, 0x00),

@@ -357,3 +297,3 @@ max: Buffer.alloc(64, 0xff),

build(id, args) {
encode(id, args) {
assert(Array.isArray(args));

@@ -380,3 +320,3 @@

parse(id, key) {
decode(id, key) {
assert(Buffer.isBuffer(key));

@@ -400,5 +340,2 @@

if (args.length === 1)
return args[0];
return args;

@@ -412,3 +349,3 @@ }

}
return this.build(id, args);
return this.encode(id, args);
}

@@ -421,3 +358,3 @@

}
return this.build(id, args);
return this.encode(id, args);
}

@@ -452,8 +389,8 @@

build(...args) {
return this.base.build(this.id, args);
encode(...args) {
return this.base.encode(this.id, args);
}
parse(key) {
return this.base.parse(this.id, key);
decode(key) {
return this.base.decode(this.id, key);
}

@@ -490,19 +427,3 @@

function sizeHex(data) {
if (Buffer.isBuffer(data))
return data.length;
assertType(typeof data === 'string');
return data.length >>> 1;
}
function writeHex(data, str, off) {
if (Buffer.isBuffer(str))
return str.copy(data, off);
assertType(typeof str === 'string');
return data.write(str, off, 'hex');
}
function sizeString(v, enc) {
if (Buffer.isBuffer(v))
return 1 + v.length;
assertType(typeof v === 'string');

@@ -518,17 +439,3 @@ return 1 + Buffer.byteLength(v, enc);

function readBuffer(k, o) {
assertLen(o + 1 <= k.length);
assertLen(o + 1 + k[o] <= k.length);
return k.slice(o + 1, o + 1 + k[o]);
}
function writeString(k, v, o, enc) {
if (Buffer.isBuffer(v)) {
assertLen(v.length <= 255);
assertLen(o + 1 <= k.length);
k[o] = v.length;
assertLen(v.copy(k, o + 1) === v.length);
return 1 + v.length;
}
assertType(typeof v === 'string');

@@ -549,5 +456,25 @@

function sizeBuffer(v) {
assertType(Buffer.isBuffer(v));
return 1 + v.length;
}
function readBuffer(k, o) {
assertLen(o + 1 <= k.length);
assertLen(o + 1 + k[o] <= k.length);
return k.slice(o + 1, o + 1 + k[o]);
}
function writeBuffer(k, v, o, enc) {
assertType(Buffer.isBuffer(v));
assertLen(v.length <= 255);
assertLen(o + 1 <= k.length);
k[o] = v.length;
assertLen(v.copy(k, o + 1) === v.length);
return 1 + v.length;
}
function assertLen(ok) {
if (!ok) {
const err = new Error('Invalid length for database key.');
const err = new RangeError('Invalid length for database key.');
if (Error.captureStackTrace)

@@ -554,0 +481,0 @@ Error.captureStackTrace(err, assertLen);

@@ -9,2 +9,5 @@ /**

module.exports = require('leveldown');
const binding = require('bindings')('leveldown').leveldown;
binding.leveldown = true;
module.exports = binding;
{
"name": "bdb",
"version": "0.2.3",
"version": "1.0.0",
"description": "Database for bcoin",

@@ -8,5 +8,3 @@ "keywords": [

"db",
"leveldb",
"leveldown",
"levelup"
"leveldb"
],

@@ -22,2 +20,3 @@ "license": "MIT",

"scripts": {
"install": "node-gyp rebuild",
"lint": "eslint lib/ || exit 0",

@@ -27,4 +26,5 @@ "test": "mocha --reporter spec test/*-test.js"

"dependencies": {
"bsert": "~0.0.3",
"leveldown": "4.0.1"
"bindings": "~1.3.0",
"bsert": "~0.0.4",
"nan": "~2.10.0"
},

@@ -38,2 +38,3 @@ "devDependencies": {

},
"gypfile": true,
"browser": {

@@ -40,0 +41,0 @@ "./lib/level": "./lib/level-browser.js"

# bdb
Database for bcoin.
Database for bcoin (leveldown backend).

@@ -9,13 +9,10 @@ ## Usage

const bdb = require('bdb');
const db = bdb.create('/path/to/my.db');
const db = bdb.create({
location: './mydb'
});
await db.open();
const root = bdb.key('r');
const rec = bdb.key('t', ['hash160', 'uint32']);
const myPrefix = bdb.key('r');
const myKey = bdb.key('t', ['hash160', 'uint32']);
const bucket = db.bucket(root.build());
const bucket = db.bucket(myPrefix.encode());
const batch = bucket.batch();

@@ -26,3 +23,3 @@

// Write `foo` to `rt[1111111111111111111111111111111111111111][00000000]`.
batch.put(rec.build(hash, 0), Buffer.from('foo'));
batch.put(myKey.encode(hash, 0), Buffer.from('foo'));

@@ -35,4 +32,4 @@ await batch.write();

const iter = bucket.iterator({
gte: rec.min(),
lte: rec.max(),
gte: myKey.min(),
lte: myKey.max(),
values: true

@@ -43,10 +40,9 @@ });

// Parse each key.
const [hash, uint] = rec.parse(key);
const [hash, index] = myKey.decode(key);
console.log('Hash: %s', hash);
console.log('Uint: %d', uint);
console.log('Value: %s', value.toString('ascii'));
console.log('Index: %d', index);
console.log('Value: %s', value.toString());
});
await db.close();
```

@@ -64,2 +60,6 @@

Parts of this software are based on leveldown:
- Copyright (c) 2017, Rod Vagg (MIT License).
See LICENSE for more info.

Sorry, the diff of this file is not supported yet

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