npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

constant-db

v2.0.4

Published

A cdb implementation for node.js

Downloads

5,368

Readme

node-constant-db Build Status

A cdb implementation in node.js, supporting both read and write capabilities.

Installation

npm install constant-db

Changes from v1.0.0

  • Renamed getRecord() to get()
  • Renamed putRecord() to put()
  • Added getNext()
  • Dropped promise support
  • Completely rewritten! get() calls should be much faster.

Example

Writable cdb:

var writable = require('constant-db').writable;

var writer = new writable('./cdbfile');
writer.open(function cdbOpened(err) {
    writer.put('meow', 'hello world');
    writer.close(function cdbClosed(err) {
        console.log('hooray!');
    });
});

Readable cdb:

var readable = require('constant-db').readable;

var reader = new readable('./cdbfile');
reader.open(function cdbOpened(err) {
    reader.get('meow', function gotRecord(err, data) {
        console.log(data); // results in 'hello world!'
        
        reader.close(function cdbClosed(err) {
            console.log('awesome!');
        });
    });
});

Documentation

Readable cdb

To create a new readable instance: new require('constant-db').readable(file);

open(callback(err, cdb))

Opens the file for reading, and immediately caches the header table for the cdb (2048 bytes).

get(key, [offset], callback(err, data))

Attempts to find the specified key, and calls the callback with an error (if not found) or the data for that key (if found). If an offset is specified, the cdb will return data for the nth record matching that key.

getNext(callback(err, data))

Continues the previous get() call, finding the next record under the key get() was called with. This should be slightly faster than calling get() with an offset.

close(callback(err, cdb))

Closes the file. No more records can be read after closing.

Writable cdb

To create a new writable instance: new require('constant-cdb').writable(file);

open(callback(err, cdb))

Opens the file for writing. This will overwrite any file that currently exists, or create a new one if necessary.

put(key, data)

Writes a record to the cdb.

close(callback(err, cdb))

Finalizes the cdb and closes the file. Calling close() is necessary to write out the header and subtables required for the cdb!

Benchmark

node benchmarks/cdb-random-benchmark.js