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

hypertrie

Package Overview
Dependencies
Maintainers
1
Versions
45
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

hypertrie - npm Package Compare versions

Comparing version 4.0.1 to 4.2.0

3

index.js

@@ -40,2 +40,3 @@ const Node = require('./lib/node')

this.metadata = opts.metadata || null
this.hash = opts.hash || null
this.valueEncoding = opts.valueEncoding ? codecs(opts.valueEncoding) : null

@@ -238,3 +239,3 @@ this.alwaysUpdate = !!opts.alwaysUpdate

if (err) return cb(err)
const node = Node.decode(val, seq, self.valueEncoding)
const node = Node.decode(val, seq, self.valueEncoding, self.hash)
// early exit for the key: '' nodes we write to reset the db

@@ -241,0 +242,0 @@ if (!node.value && !node.key) return cb(null, null)

@@ -14,3 +14,3 @@ const Put = require('./put')

this._condition = condition
this._node = new Node({key, flags: hidden ? Node.Flags.HIDDEN : 0})
this._node = new Node({key, flags: hidden ? Node.Flags.HIDDEN : 0}, null, null, db.hash)
this._length = this._node.length

@@ -17,0 +17,0 @@ this._returnClosest = closest

@@ -7,3 +7,3 @@ const Node = require('./node')

this._db = db
this._node = new Node({key, flags: (opts && opts.hidden) ? Node.Flags.HIDDEN : 0}, 0, null)
this._node = new Node({key, flags: (opts && opts.hidden) ? Node.Flags.HIDDEN : 0}, 0, null, db.hash)
this._callback = cb

@@ -10,0 +10,0 @@ this._prefix = !!(opts && opts.prefix)

@@ -14,3 +14,3 @@ const sodium = require('sodium-universal')

function Node (data, seq, enc) {
function Node (data, seq, enc, userHash) {
this.seq = seq || 0

@@ -21,3 +21,3 @@ this.key = normalizeKey(data.key)

this.flags = data.flags || 0
this.hash = hash(this.keySplit)
this.hash = userHash ? userHash(this.key) : hash(this.keySplit)
this.trie = data.trieBuffer ? trie.decode(data.trieBuffer) : (data.trie || [])

@@ -79,4 +79,4 @@ this.trieBuffer = null

Node.decode = function (buf, seq, enc) {
return new Node(messages.Node.decode(buf), seq, enc)
Node.decode = function (buf, seq, enc, hash) {
return new Node(messages.Node.decode(buf), seq, enc, hash)
}

@@ -83,0 +83,0 @@

@@ -23,3 +23,3 @@ const Node = require('./node')

this._node = new Node({key, value, valueBuffer, flags}, 0, db.valueEncoding)
this._node = new Node({key, value, valueBuffer, flags}, 0, db.valueEncoding, db.hash)
this._callback = cb

@@ -26,0 +26,0 @@ this._release = null

{
"name": "hypertrie",
"version": "4.0.1",
"version": "4.2.0",
"description": "Distributed single writer key/value store",

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

@@ -511,1 +511,48 @@ const tape = require('tape')

})
tape('can support a custom hash function', function (t) {
const db = create(null, {
valueEncoding: 'utf-8',
hash: function (key) {
return Buffer.from(key)
}
})
db.ready(function (err) {
t.error(err, 'no error')
db.put('hello', 'world', function (err) {
t.error(err, 'no error')
db.get('hello', function (err, node) {
t.error(err, 'no error')
t.same(node.value, 'world')
t.end()
})
})
})
})
tape('can delete with a custom hash function', function (t) {
const db = create(null, {
valueEncoding: 'utf-8',
hash: function (key) {
return Buffer.from(key)
}
})
db.ready(function (err) {
t.error(err, 'no error')
db.put('hello', 'world', function (err) {
t.error(err, 'no error')
db.get('hello', function (err, node) {
t.error(err, 'no error')
t.same(node.value, 'world')
db.del('hello', function (err) {
t.error(err, 'no error')
db.get('hello', function (err, node) {
t.error(err, 'no error')
t.false(node)
t.end()
})
})
})
})
})
})
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