Socket
Socket
Sign inDemoInstall

sub-encoder

Package Overview
Dependencies
2
Maintainers
2
Versions
12
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    sub-encoder

Generate sub encodings for key/value stores


Version published
Maintainers
2
Created

Readme

Source

sub-encoder

Generate sub encodings for key/value stores

Usage

const enc = new SubEncoder()
const subA = enc.sub('sub-a')
const subB = enc.sub('sub-b', 'binary') // subs support custom key encodings

await bee.put('k1', 'b')
await bee.put('a1', 'a1', { keyEncoding: subA })
await bee.put('b1', 'b1', { keyEncoding: subB })

// k1 as normal
await bee.get('k1')
// a1 from the sub
await bee.get('a1', { keyEncoding: subA })

// also supports read streams
for await (const node of bee.createReadStream({ keyEncoding: subA })) {
  // Iterates everything in the A sub
}

// The range options will be encoded properly too
for await (const node of bee.createReadStream({ lt: 'b2' }, { keyEncoding: subB })) {
}

API

const enc = new SubEncoder([prefix, encoding])

Create a new SubEncoder. Optionally set the initial prefix and encoding.

prefix can be string or Buffer. If set, acts as an initial sub instead of starting at the Hyperbee's base level.

subEnc = enc.sub(prefix, [encoding])

Make a new sub. Returns a SubEncoder, so subs can easily be nested.

prefix can be string or Buffer.

buf = enc.encode(key)

Encode a key.

key = enc.decode(buf)

Decode a key.

encodedRange = enc.encodeRange(range)

Encode a range.

License

Apache-2.0

Keywords

FAQs

Last updated on 10 Oct 2023

Did you know?

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

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc