@foxglove/rosbag 
@foxglove/rosbag
is a node.js & browser compatible module for reading rosbag binary data files.
Installation
npm install @foxglove/rosbag
or
yarn add @foxglove/rosbag
Quick start
The most common way to interact with a rosbag is to read data records for a specific set of topics. The rosbag format encodes type information for topics, and rosbag
reads this type information and parses the data records into JavaScript objects and arrays.
Here is an example of reading messages from a rosbag in node.js:
import { Bag } from "@foxglove/rosbag";
import { FileReader } from "@foxglove/rosbag/node";
async function logMessagesFromFooBar() {
const bag = new Bag(new FileReader("../path/to/ros.bag"));
await bag.open();
for await (const result of bag.messageIterator({ topics: ["/foo", "/bar"] })) {
console.log(result.topic);
console.log(result.message);
}
}
logMessagesFromFooBar();
API
Bag instance
class Bag {
startTime: Time,
endTime: Time,
connections: { [number]: Connection },
chunkInfos: Array<ChunkInfo>,
}
BagOptions
const options = {
decompress?: {
bz2?: (buffer: Uint8Array, uncompressedByteLength: number) => Uint8Array,
lz4?: (buffer: Uint8Array, uncompressedByteLength: number) => Uint8Array,
},
parse?: boolean;
}
Consuming messages from the bag instance
bag.messageIterator
method returns an Async Iterator for messages in the file. Each item is a MessageEvent
.
IteratorOptions
const options {
topics?: Array<string>,
start?: Time,
}
MessageEvent
const messageEvent {
topic: string,
timestamp: Time
data: Uint8Array,
message?: { [string]: unknown },
}
Connection
class Connection {
conn: number,
topic: string,
md5sum: string,
messageDefinition: string,
}
Stay in touch
Join our Slack channel to ask questions, share feedback, and stay up to date on what our team is working on.