From 1d59865447b7f8eb44c0966e0f8991518a3adf37 Mon Sep 17 00:00:00 2001 From: Mathias Buus Date: Mon, 18 Mar 2024 22:07:29 +0100 Subject: [PATCH] fwd the memory vfs --- index.js | 3 +++ memory.js | 12 ++++++++++++ 2 files changed, 15 insertions(+) diff --git a/index.js b/index.js index 460a7d3..c26ed40 100644 --- a/index.js +++ b/index.js @@ -1,3 +1,4 @@ +const MemoryVFS = require('./memory') const ReadyResource = require('ready-resource') const binding = require.addon() @@ -15,6 +16,8 @@ module.exports = class BareSQLite3 extends ReadyResource { this._result = null } + static MemoryVFS = MemoryVFS + _open () { binding.bare_sqlite3_open( this._handle, diff --git a/memory.js b/memory.js index 529d293..2f3ed36 100644 --- a/memory.js +++ b/memory.js @@ -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) }