Socket
Socket
Sign inDemoInstall

hyperbee

Package Overview
Dependencies
Maintainers
1
Versions
108
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

hyperbee - npm Package Compare versions

Comparing version 0.0.0 to 0.0.1

iterators/history.js

58

index.js
const codecs = require('codecs')
const { Readable } = require('streamx')
const RangeIterator = require('./iterators/range')
const HistoryIterator = require('./iterators/history')
const Extension = require('./lib/extension')
const { YoloIndex, Node } = require('./messages')
const { YoloIndex, Node, Header } = require('./lib/messages')

@@ -230,3 +231,3 @@ const T = 5

class BTree {
class HyperBee {
constructor (feed, opts = {}) {

@@ -254,3 +255,3 @@ this.feed = feed

if (this.feed.length > 0 || !this.feed.writable) return resolve()
this.feed.append('header', (err) => {
this.feed.append(Header.encode({ protocol: 'hyperbee' }), (err) => {
if (err) return reject(err)

@@ -290,3 +291,3 @@ resolve()

if (this.keyEncoding) entry.key = this.keyEncoding.decode(entry.key)
if (this.valueEncoding) entry.value = this.valueEncoding.decode(entry.value)
if (this.valueEncoding && entry.value) entry.value = this.valueEncoding.decode(entry.value)
resolve(new BlockEntry(seq, batch, entry))

@@ -301,23 +302,4 @@ })

createHistoryStream () {
let seq = 1
const tree = this
return new Readable({
open (cb) {
tree.feed.ready(cb)
},
read (cb) {
if (seq >= tree.feed.length) {
this.push(null)
return cb(null)
}
tree.feed.get(seq, { valueEncoding: Node }, (err, data) => {
if (err) return cb(err)
this.push(new BlockEntry(seq++, tree, data))
cb(null)
})
}
})
createHistoryStream (opts) {
return iteratorToStream(new HistoryIterator(new Batch(this, false, false, opts), opts))
}

@@ -345,3 +327,3 @@

checkout (version) {
return new BTree(this.feed, {
return new HyperBee(this.feed, {
checkout: version,

@@ -357,17 +339,2 @@ extension: this.extension,

}
async debugToString () {
return require('tree-to-string')(await load(await this.getRoot()))
async function load (node) {
const res = { values: [], children: [] }
for (let i = 0; i < node.keys.length; i++) {
res.values.push((await node.getKey(i)).toString())
}
for (let i = 0; i < node.children.length; i++) {
res.children.push(await load(await node.getChildNode(i)))
}
return res
}
}
}

@@ -391,2 +358,6 @@

get version () {
return this.tree.version + this.length
}
getRoot () {

@@ -455,2 +426,3 @@ if (this.root !== null) return this.root

if (typeof key === 'string') key = Buffer.from(key)
if (value && this.valueEncoding) value = this.valueEncoding.encode(value)

@@ -607,3 +579,3 @@ const stack = []

key: this.tree.keyEncoding ? this.tree.keyEncoding.encode(key) : key,
value: this.tree.valueEncoding ? this.tree.valueEncoding.encode(value) : value,
value,
index: deflate(index)

@@ -729,2 +701,2 @@ }))

module.exports = BTree
module.exports = HyperBee

@@ -1,2 +0,2 @@

const { Extension } = require('../messages')
const { Extension } = require('./messages')

@@ -3,0 +3,0 @@ class Batch {

{
"name": "hyperbee",
"version": "0.0.0",
"description": "",
"version": "0.0.1",
"description": "An append-only Btree running on a Hypercore.",
"main": "index.js",

@@ -9,15 +9,26 @@ "dependencies": {

"protocol-buffers-encodings": "^1.1.0",
"streamx": "^2.6.6",
"tree-to-string": "^1.1.1"
"streamx": "^2.6.6"
},
"devDependencies": {
"hypercore": "^9.5.0",
"protocol-buffers": "^4.2.0",
"random-access-memory": "^3.1.1",
"tape": "^5.0.1"
"standard": "^14.3.4",
"tape": "^5.0.1",
"tree-to-string": "^1.1.1"
},
"scripts": {
"test": "tape test/*.js"
"test": "standard && tape test/*.js",
"protobuf": "protocol-buffers schema.proto -o ./lib/messages.js"
},
"author": "",
"license": "ISC"
"repository": {
"type": "git",
"url": "https://github.com/mafintosh/hyperbee.git"
},
"author": "Mathias Buus (@mafintosh)",
"license": "MIT",
"bugs": {
"url": "https://github.com/mafintosh/hyperbee/issues"
},
"homepage": "https://github.com/mafintosh/hyperbee"
}

Sorry, the diff of this file is not supported yet

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