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

sub-encoder

Package Overview
Dependencies
Maintainers
1
Versions
12
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

sub-encoder - npm Package Compare versions

Comparing version 1.0.0 to 1.0.1

5

index.js

@@ -42,2 +42,7 @@ const isOptions = require('is-options')

sub (prefix, opts) {
if (isOptions(prefix)) {
opts = prefix
prefix = null
}
if (!prefix) prefix = ''
if (typeof prefix === 'string') {

@@ -44,0 +49,0 @@ prefix = b.from(prefix)

2

package.json
{
"name": "sub-encoder",
"version": "1.0.0",
"version": "1.0.1",
"description": "Generate sub encodings for key/value stores",

@@ -5,0 +5,0 @@ "main": "index.js",

@@ -10,13 +10,13 @@ # sub-encoder

await bee.put(enc.encodeKey('k1'), 'b')
await bee.put(subA.encodeKey('a1'), 'a1')
await bee.put(subB.encodeKey('b1'), 'b1')
await bee.put('k1', 'b', { keyEncoding: enc })
await bee.put('a1', 'a1', { keyEncoding: subA })
await bee.put('b1', 'b1' { keyEncoding: subB })
// k1
await bee.get(enc.encodeKey('k1'))
await bee.get('k1', { keyEncoding: enc })
// a1
await bee.get(subA.encodeKey('a1'))
await bee.get('a1', { keyEncoding: subA })
// also supports read streams
for await (const node of bee.createReadStream(subA.encodeRange())) {
for await (const node of bee.createReadStream(subA.range())) {
// Iterates everything in the A sub

@@ -26,3 +26,3 @@ }

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

@@ -29,0 +29,0 @@ ```

@@ -87,2 +87,41 @@ const test = require('brittle')

test('supports the empty sub', async t => {
const bee = new Hyperbee(new Hypercore(ram))
const enc = new SubEncoder()
const sub1 = enc.sub('1', { keyEncoding: 'utf-8' })
const sub2 = enc.sub('2', { keyEncoding: 'utf-8' })
const sub3 = enc.sub()
await bee.put('', b.from('a'), { keyEncoding: sub1 })
await bee.put('', b.from('b'), { keyEncoding: sub2 })
await bee.put(b.alloc(1), b.from('c'), { keyEncoding: sub3 })
const n3 = await collect(bee.createReadStream(sub3.range()))
t.is(n3.length, 1)
t.alike(n3[0].key, b.alloc(1))
})
test('can read out the empty key in subs', async t => {
const bee = new Hyperbee(new Hypercore(ram))
const enc = new SubEncoder()
const sub1 = enc.sub('1', { keyEncoding: 'utf-8' })
const sub2 = enc.sub('2', { keyEncoding: 'utf-8' })
const sub3 = enc.sub('3', { keyEncoding: 'binary' })
await bee.put('', b.from('a'), { keyEncoding: sub1 })
await bee.put('', b.from('b'), { keyEncoding: sub2 })
await bee.put(b.alloc(1), b.from('c'), { keyEncoding: sub3 })
const n1 = await collect(bee.createReadStream(sub1.range()))
const n2 = await collect(bee.createReadStream(sub2.range()))
const n3 = await collect(bee.createReadStream(sub3.range()))
t.is(n1[0].key, '')
t.is(n2[0].key, '')
t.alike(n3[0].key, b.alloc(1))
})
async function collect (ite) {

@@ -89,0 +128,0 @@ const res = []

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