Comparing version 0.0.2 to 0.0.3
@@ -5,3 +5,3 @@ const hypercore = require('hypercore') | ||
const swarm = require('@hyperswarm/replicator')(db.feed, { | ||
require('@hyperswarm/replicator')(db.feed, { | ||
announce: true, | ||
@@ -12,4 +12,4 @@ lookup: true, | ||
let bytes = 0 | ||
let blocks = 0 | ||
// let bytes = 0 | ||
// let blocks = 0 | ||
@@ -36,3 +36,2 @@ // db.feed.on('download', function (index, buf) { | ||
const times = [] | ||
@@ -39,0 +38,0 @@ for (const id of ids) { |
@@ -32,2 +32,3 @@ const Hyperb = require('../../') | ||
primaryTitle, | ||
originalTitle, | ||
isAdult: isAdult !== '0', | ||
@@ -34,0 +35,0 @@ startYear: startYear === '\\N' ? 0 : Number(startYear), |
29
index.js
@@ -210,2 +210,10 @@ const codecs = require('codecs') | ||
final () { | ||
return { | ||
seq: this.seq, | ||
key: this.tree.keyEncoding ? this.tree.keyEncoding.decode(this.key) : this.key, | ||
value: this.value && (this.tree.valueEncoding ? this.tree.valueEncoding.decode(this.value) : this.value) | ||
} | ||
} | ||
getTreeNode (offset) { | ||
@@ -289,4 +297,2 @@ if (this.index === null) { | ||
if (err) return reject(err) | ||
if (this.keyEncoding) entry.key = this.keyEncoding.decode(entry.key) | ||
if (this.valueEncoding && entry.value) entry.value = this.valueEncoding.decode(entry.value) | ||
resolve(new BlockEntry(seq, batch, entry)) | ||
@@ -341,2 +347,4 @@ }) | ||
this.tree = tree | ||
this.keyEncoding = tree.keyEncoding | ||
this.valueEncoding = tree.valueEncoding | ||
this.blocks = cache ? new Map() : null | ||
@@ -406,3 +414,3 @@ this.autoFlush = autoFlush | ||
if (c === 0) { | ||
return this.getBlock(node.keys[mid].seq) | ||
return (await this.getBlock(node.keys[mid].seq)).final() | ||
} | ||
@@ -421,5 +429,12 @@ | ||
_enc (enc, v) { | ||
if (v === undefined || v === null) return null | ||
if (enc !== null) return enc.encode(v) | ||
if (typeof v === 'string') return Buffer.from(v) | ||
return v | ||
} | ||
async put (key, value) { | ||
if (typeof key === 'string') key = Buffer.from(key) | ||
if (value && this.valueEncoding) value = this.valueEncoding.encode(value) | ||
key = this._enc(this.keyEncoding, key) | ||
value = this._enc(this.valueEncoding, value) | ||
@@ -482,3 +497,3 @@ const stack = [] | ||
async del (key) { | ||
if (typeof key === 'string') key = Buffer.from(key) | ||
key = this._enc(this.keyEncoding, key) | ||
@@ -575,3 +590,3 @@ const stack = [] | ||
return this._appendBatch(Node.encode({ | ||
key: this.tree.keyEncoding ? this.tree.keyEncoding.encode(key) : key, | ||
key, | ||
value, | ||
@@ -578,0 +593,0 @@ index: deflate(index) |
@@ -26,8 +26,8 @@ module.exports = class HistoryIterator { | ||
if (this.since < 1) return null | ||
return this.db.getBlock(this.since--, this.options) | ||
return (await this.db.getBlock(this.since--, this.options)).final() | ||
} | ||
if (this.since >= this.end) return null | ||
return this.db.getBlock(this.since++, this.options) | ||
return (await this.db.getBlock(this.since++, this.options)).final() | ||
} | ||
} |
@@ -48,3 +48,3 @@ module.exports = class RangeIterator { | ||
let i = c < 0 ? e : s | ||
const i = c < 0 ? e : s | ||
entry.i = 2 * i + (this._reverse ? -1 : 1) | ||
@@ -93,3 +93,3 @@ | ||
if (this._limit > 0) this._limit-- | ||
return block | ||
return block.final() | ||
} | ||
@@ -96,0 +96,0 @@ |
@@ -74,3 +74,1 @@ const { Extension } = require('./messages') | ||
} | ||
function noop () {} |
{ | ||
"name": "hyperbee", | ||
"version": "0.0.2", | ||
"version": "0.0.3", | ||
"description": "An append-only Btree running on a Hypercore.", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -14,3 +14,6 @@ # Hyperbee 🐝 | ||
const Hyperbee = require('hyperbee') | ||
const db = new Hyperbee(feed) | ||
const db = new Hyperbee(feed, { | ||
keyEncoding: 'utf-8', // can be set to undefined (binary), utf-8, ascii or and abstract-encoding | ||
valueEncoding: 'binary' // same options as above | ||
}) | ||
@@ -17,0 +20,0 @@ // if you own the feed |
@@ -118,3 +118,3 @@ const tape = require('tape') | ||
const end = opts.lt ? reference.indexOf(opts.lt) : reference.indexOf(opts.lte) + 1 | ||
let range = reference.slice(start, end) | ||
const range = reference.slice(start, end) | ||
if (opts.reverse) range.reverse() | ||
@@ -128,3 +128,3 @@ for (let i = 0; i < range.length; i++) { | ||
console.log(' actual:', entries.map(e => e.key)) | ||
t.fail(`ranges did not match`) | ||
t.fail('ranges did not match') | ||
return false | ||
@@ -131,0 +131,0 @@ } |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
43
54528
16
1669