Skip to content

Commit

Permalink
fwd the memory vfs
Browse files Browse the repository at this point in the history
  • Loading branch information
mafintosh committed Mar 18, 2024
1 parent 658ef11 commit 1d59865
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
3 changes: 3 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
const MemoryVFS = require('./memory')
const ReadyResource = require('ready-resource')
const binding = require.addon()

Expand All @@ -15,6 +16,8 @@ module.exports = class BareSQLite3 extends ReadyResource {
this._result = null
}

static MemoryVFS = MemoryVFS

_open () {
binding.bare_sqlite3_open(
this._handle,
Expand Down
12 changes: 12 additions & 0 deletions memory.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,18 @@ module.exports = class MemoryVFS {
this.size = 0
}

pages ({ copy = true } = {}) {
const all = []
for (let i = 0; i < this.buffer.byteLength; i += 4096) {
const value = this.buffer.subarray(i, i + 4096)
all.push({
index: i / 4096,
value: copy ? Buffer.concat([value]) : value
})
}
return all
}

read (start, end) {
return this.buffer.subarray(start, end)
}
Expand Down

0 comments on commit 1d59865

Please sign in to comment.