@foxglove/rosbag2-web
Advanced tools
Comparing version 0.1.4 to 0.2.0
import { Filelike, MessageReadOptions, RawMessage, SqliteDb, TopicDefinition } from "@foxglove/rosbag2"; | ||
import { Time } from "@foxglove/rostime"; | ||
declare type LocateWasmUrl = (url: string, scriptDirectory: string) => string; | ||
export declare class SqliteSqljs implements SqliteDb { | ||
readonly file: Readonly<Filelike>; | ||
private locateSqlJsWasm?; | ||
private sqlJsWasm?; | ||
private context?; | ||
constructor(file: Filelike, locateSqlJsWasm?: (file: string) => string); | ||
constructor(file: Filelike, sqlJsWasm?: LocateWasmUrl | ArrayBuffer); | ||
open(): Promise<void>; | ||
@@ -15,2 +16,3 @@ close(): Promise<void>; | ||
} | ||
export {}; | ||
//# sourceMappingURL=SqliteSqljs.d.ts.map |
@@ -11,8 +11,17 @@ "use strict"; | ||
class SqliteSqljs { | ||
constructor(file, locateSqlJsWasm) { | ||
constructor(file, sqlJsWasm) { | ||
this.file = file; | ||
this.locateSqlJsWasm = locateSqlJsWasm; | ||
this.sqlJsWasm = sqlJsWasm; | ||
} | ||
async open() { | ||
const SQL = await sql_js_1.default({ locateFile: this.locateSqlJsWasm }); | ||
const initOpts = {}; | ||
if (this.sqlJsWasm != undefined) { | ||
if (this.sqlJsWasm instanceof ArrayBuffer) { | ||
initOpts.wasmBinary = this.sqlJsWasm; | ||
} | ||
else { | ||
initOpts.locateFile = this.sqlJsWasm; | ||
} | ||
} | ||
const SQL = await sql_js_1.default(initOpts); | ||
const data = await this.file.read(); | ||
@@ -19,0 +28,0 @@ const db = new SQL.Database(new Uint8Array(data)); |
@@ -65,2 +65,9 @@ "use strict"; | ||
}); | ||
it("should open a database using a passed in wasm ArrayBuffer", async () => { | ||
const wasmPath = path_1.default.join(__dirname, "..", "node_modules", "sql.js", "dist", "sql-wasm.wasm"); | ||
const wasm = await promises_1.readFile(wasmPath); | ||
const db = new SqliteSqljs_1.SqliteSqljs(new FsReader(TALKER_DB), wasm); | ||
await db.open(); | ||
await db.close(); | ||
}); | ||
it("should read all topics", async () => { | ||
@@ -67,0 +74,0 @@ const db = new SqliteSqljs_1.SqliteSqljs(new FsReader(TALKER_DB)); |
{ | ||
"name": "@foxglove/rosbag2-web", | ||
"version": "0.1.4", | ||
"version": "0.2.0", | ||
"description": "ROS2 (Robot Operating System) bag reader and writer for the browser", | ||
@@ -5,0 +5,0 @@ "license": "MIT", |
@@ -83,2 +83,10 @@ import { | ||
it("should open a database using a passed in wasm ArrayBuffer", async () => { | ||
const wasmPath = path.join(__dirname, "..", "node_modules", "sql.js", "dist", "sql-wasm.wasm"); | ||
const wasm = await readFile(wasmPath); | ||
const db = new SqliteSqljs(new FsReader(TALKER_DB), wasm); | ||
await db.open(); | ||
await db.close(); | ||
}); | ||
it("should read all topics", async () => { | ||
@@ -85,0 +93,0 @@ const db = new SqliteSqljs(new FsReader(TALKER_DB)); |
@@ -30,14 +30,24 @@ import { | ||
type LocateWasmUrl = (url: string, scriptDirectory: string) => string; | ||
export class SqliteSqljs implements SqliteDb { | ||
readonly file: Readonly<Filelike>; | ||
private locateSqlJsWasm?: (file: string) => string; | ||
private sqlJsWasm?: LocateWasmUrl | ArrayBuffer; | ||
private context?: DbContext; | ||
constructor(file: Filelike, locateSqlJsWasm?: (file: string) => string) { | ||
constructor(file: Filelike, sqlJsWasm?: LocateWasmUrl | ArrayBuffer) { | ||
this.file = file; | ||
this.locateSqlJsWasm = locateSqlJsWasm; | ||
this.sqlJsWasm = sqlJsWasm; | ||
} | ||
async open(): Promise<void> { | ||
const SQL = await initSqlJs({ locateFile: this.locateSqlJsWasm }); | ||
const initOpts: Partial<EmscriptenModule> = {}; | ||
if (this.sqlJsWasm != undefined) { | ||
if (this.sqlJsWasm instanceof ArrayBuffer) { | ||
initOpts.wasmBinary = this.sqlJsWasm; | ||
} else { | ||
initOpts.locateFile = this.sqlJsWasm; | ||
} | ||
} | ||
const SQL = await initSqlJs(initOpts); | ||
@@ -44,0 +54,0 @@ const data = await this.file.read(); |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
69704
1083
0