Skip to content

Instantly share code, notes, and snippets.

@defunctzombie
Last active December 16, 2021 02:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save defunctzombie/13b3e1d7717d9855b6a076e966e5cdf4 to your computer and use it in GitHub Desktop.
Save defunctzombie/13b3e1d7717d9855b6a076e966e5cdf4 to your computer and use it in GitHub Desktop.
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 });
};
{
"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"
}
}
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()],
};
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