Last active
December 16, 2021 02:45
-
-
Save defunctzombie/13b3e1d7717d9855b6a076e966e5cdf4 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const worker = new Worker(new URL("./worker.js", import.meta.url)); | |
const input = document.createElement("input"); | |
input.type = "file"; | |
document.body.appendChild(input); | |
input.onchange = (ev) => { | |
const file = ev.target.files[0]; | |
worker.postMessage({ file }); | |
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"scripts": { | |
"dev": "yarn webpack serve --hot --mode development" | |
}, | |
"dependencies": { | |
"@foxglove/sql.js": "^0.0.2", | |
"webpack": "^5.65.0" | |
}, | |
"devDependencies": { | |
"html-webpack-plugin": "^5.5.0", | |
"webpack-cli": "^4.9.1", | |
"webpack-dev-server": "^4.6.0" | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const HtmlWebpackPlugin = require("html-webpack-plugin"); | |
module.exports = { | |
module: { | |
rules: [ | |
{ | |
test: /\.wasm$/, | |
type: "asset/resource", | |
}, | |
], | |
}, | |
resolve: { | |
fallback: { | |
path: false, | |
fs: false, | |
crypto: false, | |
}, | |
}, | |
plugins: [new HtmlWebpackPlugin()], | |
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { SqliteSqljs } from "@foxglove/rosbag2-web"; | |
import { Rosbag2 } from "@foxglove/rosbag2"; | |
async function main() { | |
const res = await fetch( | |
new URL("@foxglove/sql.js/dist/sql-wasm.wasm", import.meta.url).toString() | |
); | |
const sqlWasm = await (await res.blob()).arrayBuffer(); | |
await SqliteSqljs.Initialize({ | |
wasmBinary: sqlWasm, | |
}); | |
self.onmessage = async (ev) => { | |
const file = ev.data.file; | |
const dbFile = new SqliteSqljs(file); | |
const bag = new Rosbag2([dbFile]); | |
await bag.open(); | |
const topics = await bag.readTopics(); | |
console.log("bag topics", { topics }); | |
let count = 0; | |
for await (const msg of bag.readMessages({ rawMessages: true })) { | |
count += 1; | |
console.log(count); | |
} | |
}; | |
} | |
void main(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment