Skip to content

Commit

Permalink
rename core storage close to destroy
Browse files Browse the repository at this point in the history
  • Loading branch information
chm-diederichs committed Oct 31, 2024
1 parent d5b26c8 commit 8897bd9
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 18 deletions.
26 changes: 13 additions & 13 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -415,7 +415,7 @@ class HypercoreStorage {
this.corePointer = core
this.dataPointer = data

this.closed = false
this.destroyed = false
}

get snapshotted () {
Expand Down Expand Up @@ -476,30 +476,30 @@ class HypercoreStorage {
}

snapshot () {
assert(this.closed === false)
assert(this.destroyed === false)
return new HypercoreStorage(this.root, this.discoveryKey, this.corePointer, this.dataPointer, this.db.snapshot())
}

createReadBatch (opts) {
assert(this.closed === false)
assert(this.destroyed === false)

const snapshot = this.dbSnapshot
return new ReadBatch(this, this.db.read({ snapshot }))
}

createWriteBatch () {
assert(this.closed === false)
assert(this.destroyed === false)

return new WriteBatch(this, this.db.write())
}

createBlockStream (opts = {}) {
assert(this.closed === false)
assert(this.destroyed === false)
return createStream(this, createBlockStream, opts)
}

createUserDataStream (opts = {}) {
assert(this.closed === false)
assert(this.destroyed === false)

const r = encodeIndexRange(this.dataPointer, DATA.USER_DATA, this.dbSnapshot, opts)
const s = this.db.iterator(r)
Expand All @@ -508,7 +508,7 @@ class HypercoreStorage {
}

createTreeNodeStream (opts = {}) {
assert(this.closed === false)
assert(this.destroyed === false)

const r = encodeIndexRange(this.dataPointer, DATA.TREE, this.dbSnapshot, opts)
const s = this.db.iterator(r)
Expand All @@ -517,7 +517,7 @@ class HypercoreStorage {
}

createBitfieldPageStream (opts = {}) {
assert(this.closed === false)
assert(this.destroyed === false)

const r = encodeIndexRange(this.dataPointer, DATA.BITFIELD, this.dbSnapshot, opts)
const s = this.db.iterator(r)
Expand All @@ -526,24 +526,24 @@ class HypercoreStorage {
}

async peekLastTreeNode () {
assert(this.closed === false)
assert(this.destroyed === false)

const last = await this.db.peek(encodeIndexRange(this.dataPointer, DATA.TREE, this.dbSnapshot, { reverse: true }))
if (last === null) return null
return c.decode(m.TreeNode, last.value)
}

async peekLastBitfieldPage () {
assert(this.closed === false)
assert(this.destroyed === false)

const last = await this.db.peek(encodeIndexRange(this.dataPointer, DATA.BITFIELD, this.dbSnapshot, { reverse: true }))
if (last === null) return null
return mapStreamBitfieldPage(last)
}

close () {
if (this.closed) return
this.closed = true
destroy () {
if (this.destroyed) return
this.destroyed = true

if (this.dbSnapshot) this.dbSnapshot.destroy()
this.dbSnapshot = null
Expand Down
4 changes: 1 addition & 3 deletions lib/memory-overlay.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,9 +75,7 @@ class MemoryOverlay {
return (page && (!disk || index > disk.index)) ? { index, page } : disk
}

close () {
return Promise.resolve()
}
destroy () {}

merge (overlay) {
if (overlay.head !== null) this.head = overlay.head
Expand Down
4 changes: 2 additions & 2 deletions test/basic.js
Original file line number Diff line number Diff line change
Expand Up @@ -700,7 +700,7 @@ test('reopen default core', async function (t) {
const s1 = await getStorage(t, dir)
const c1 = (await s1.resume(DK_1)) || (await s1.create({ key: DK_1, discoveryKey: DK_1, manifest, keyPair, encryptionKey }))

await c1.close()
await c1.destroy()
await s1.close()

const s2 = await getStorage(t, dir)
Expand Down Expand Up @@ -732,7 +732,7 @@ test('large manifest', async function (t) {
const s1 = await getStorage(t, dir)
const c1 = (await s1.resume(DK_1)) || (await s1.create({ key: DK_1, discoveryKey: DK_1, manifest, keyPair, encryptionKey }))

await c1.close()
await c1.destroy()
await s1.close()

const s2 = await getStorage(t, dir)
Expand Down

0 comments on commit 8897bd9

Please sign in to comment.