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

bdb

Package Overview
Dependencies
Maintainers
1
Versions
29
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

bdb

Database for bcoin

  • 0.1.0
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
327
decreased by-8.4%
Maintainers
1
Weekly downloads
 
Created
Source

bdb

Database for bcoin.

Usage

const bdb = require('bdb');

const db = bdb.create({
  location: './mydb'
});

await db.open();

const root = bdb.key('r');
const rec = bdb.key('t', ['hash160', 'uint32']);

const bucket = db.bucket(root.build());
const batch = bucket.batch();

const hash = Buffer.alloc(20, 0x11);

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

await batch.write();

// Iterate:
// From: `rt[0000000000000000000000000000000000000000][00000000]`
// To: `rt[ffffffffffffffffffffffffffffffffffffffff][ffffffff]`
const iter = bucket.iterator({
  gte: rec.min(),
  lte: rec.max(),
  values: true
});

await iter.each((key, value) => {
  // Parse each key.
  const [hash, uint] = rec.parse(key);
  console.log('Hash: %s', hash);
  console.log('Uint: %d', uint);
  console.log('Value: %s', value.toString('ascii'));
});

await db.close();

Contribution and License Agreement

If you contribute code to this project, you are implicitly allowing your code to be distributed under the MIT license. You are also implicitly verifying that all code is your original work. </legalese>

License

  • Copyright (c) 2017, Christopher Jeffrey (MIT License).

See LICENSE for more info.

Keywords

FAQs

Package last updated on 06 Apr 2018

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

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