;(async function() {
const Corestore = require('corestore');
const Hyperdrive = require('hyperdrive');
const folder = 'animals';
const store = new Corestore(`./db/${folder}`);
await store.ready();
const drive = new Hyperdrive(store);
await drive.ready();
await drive.put(`/dogs/husky`, Buffer.from(JSON.stringify({ _id: 'husky', job: 'sled dog' })));
await drive.put(`/dogs/husky`, Buffer.from(JSON.stringify({ _id: 'husky', job: 'sled dog', origin: 'siberia' })));
await drive.put(`/dogs/husky`, Buffer.from(JSON.stringify({ _id: 'husky', job: 'sled dog', origin: 'siberia', size: 'medium' })));
console.log(JSON.parse((await drive.get(`/dogs/husky`)).toString()));
const trim = drive.db.core.length; // keep tiny on startup
console.log(1, trim);
const view = drive.db.createReadStream();
const blobs = await drive.getBlobs();
for await (const entry of view) {
console.log(entry);
const key = entry.key.replace('files\x00', '');
const value = await blobs.get(entry.value.blob);
console.log(key, value.toString());
await drive.put(key, value);
}
await drive.db.core.clear(1, trim);
console.log(JSON.parse((await drive.get(`/dogs/husky`)).toString()));
console.log((await drive.db.core.get(0, {wait: false})).toString()); // hyperbee
console.log((await drive.db.core.get(1, {wait: false})).toString()); // files/dogs/husky|{"exec... // I expected null
console.log((await drive.db.core.get(2, {wait: false})).toString()); // files/dogs/husky}{"exec... // I expected null
console.log((await drive.db.core.get(3, {wait: false})).toString()); // files/dogs/husky}{"exec... // I expected null
console.log((await drive.db.core.get(4, {wait: false})).toString()); // files/dogs/husky~{"exec...
})();