holepunchto/hyperbee

Values stored as keys when using sub of sub

Closed this issue · 3 comments

I'm getting values stored as keys when using sub, minimal example to reproduce:

let Hypercore = require('hypercore');
let Hyperbee = require('hyperbee');
let myCore = new Hypercore('/myCore2', {valueEncoding: 'utf-8'})
let myBee
let a
myCore.ready(async () => {
	console.log('core ready')
	myBee = new Hyperbee(myCore,{keyEncoding: 'utf-8', valueEncoding: 'binary'})
	await myBee.ready()
	console.log('bee ready')
	let mySubBee = myBee.sub(myCore.key.toString('hex'))
	let mySubSubBee = myBee.sub('fe766f9a420f08c28f4c067fd7a5a01f86aa6e198e44dd68af1470c1db611c09')
	await mySubSubBee.put('e3e03a4a511d49a87468f13d1aa297081812d51e6138cfc70071d237a561a2c9','testvalue')
	await mySubSubBee.put('ca7bd4311e9d21e4c8d04162970998d715b8b92c92ee4ff434357f312647b401','anothertestvalue')
	for await (let val of mySubSubBee.createReadStream()){
		console.log(val)
	}		
});

Gives:

{
  seq: 2,
  key: 'ca7bd4311e9d21e4c8d04162970998d715b8b92c92ee4ff434357f312647b401\x1A\x10anothertestvalue',
  value: null
}
{
  seq: 1,
  key: 'e3e03a4a511d49a87468f13d1aa297081812d51e6138cfc70071d237a561a2c9\x1A\ttestvalue',
  value: null
}

I expected the value fields to be populated with testvalue and anothertestvalue

Can you clean up the formatting? A bit hard to read.

Can you clean up the formatting? A bit hard to read.

Done

/```\n

was the key

let myCore = new Hypercore('/myCore2', {valueEncoding: 'utf-8'})

is wrong. Don't set the encoding on the core itself when using bee, as that'll corrupt it. Just do

let myCore = new Hypercore('/myCore2')