Socket
Socket
Sign inDemoInstall

buffer-prefix-range

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

buffer-prefix-range

Easily define lexicographical ranges of byte strings using a prefix. Can be used to define ranges for queries in leveldb or similar databases


Version published
Maintainers
1
Created
Source

buffer-prefix-range

Easily define lexicographical ranges of byte strings using a prefix. Can be used to define ranges for queries in leveldb or similar databases.

Node.js:

Build Status

Browsers:

Selenium Test Status

Installation

npm install --save buffer-prefix-range

Usage

This library has one function which accepts a bytestring - 'prefix' - and returns an object that:

  • Contains two other bytestrings - 'start' and 'end' - where the set of all bytestrings whose prefix are equal to 'prefix' is bounded by 'start' and exclusively bounded by 'end'. In other words, if a bytestring is prefixed by 'prefix' then it will be greater or equal than 'start' and lesser than 'end'(lexicographically).

  • Has a method 'contains' that tells if a bytestring is contained within the lexicographical range of 'start' and 'end'

Its main use case is to create queries in leveldb-style dbs(databases that have arbitrary bytestrings as keys) that filter out keys that are not prefixed by a certain key prefix. For example:

> var level = require('level');
> db = level('./mydb');
> db.put('foo', ...);
> db.put('foobar', ...);
> db.put('foofoo', ...);
> db.put('fobar', ...);

Then suppose you want to query all entries that start with 'foo':

> var bytePrefixRange = require('byte-prefix-range');
> var range = bytePrefixRange('foo');
> db.createReadStream({start: range.start, end: range.end});
// will return 'foo', 'foobar' and 'foofoo'

Buffer objects or strings(which will be utf8-encoded) prefixes can be used.

Keywords

FAQs

Package last updated on 19 Dec 2013

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