Skip to content

Commit

Permalink
Fix startTime and endTime computation when chunks are not sorted (#111)
Browse files Browse the repository at this point in the history
* Fix startTime and endTime computation when chunks are not sorted

* Bump version
  • Loading branch information
pankdm authored Jun 22, 2022
1 parent 66e06ae commit 8d295a0
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 3 deletions.
Binary file added fixtures/example-unsorted-chunks.bag
Binary file not shown.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "rosbag",
"version": "3.0.0",
"version": "3.0.1",
"license": "Apache-2.0",
"repository": "cruise-automation/rosbag.js",
"dependencies": {
Expand Down
10 changes: 8 additions & 2 deletions src/bag.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,14 @@ export default class Bag {
this.chunkInfos = result.chunkInfos;

if (chunkCount > 0) {
this.startTime = this.chunkInfos[0].startTime;
this.endTime = this.chunkInfos[chunkCount - 1].endTime;
// Get the earliest startTime among all chunks
this.startTime = this.chunkInfos
.map((x) => x.startTime)
.reduce((prev, current) => (TimeUtil.compare(prev, current) <= 0 ? prev : current));
// Get the latest endTime among all chunks
this.endTime = this.chunkInfos
.map((x) => x.endTime)
.reduce((prev, current) => (TimeUtil.compare(prev, current) > 0 ? prev : current));
}
}

Expand Down
8 changes: 8 additions & 0 deletions src/bag.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,14 @@ describe("rosbag - high-level api", () => {
expect(messages).toHaveLength(9);
});

it("computes start and end time for unsorted chunks", async () => {
const filename = getFixture("example-unsorted-chunks");
expect(fs.existsSync(filename)).toBe(true);
const bag = await Bag.open(filename);
expect(bag.startTime).toEqual({ sec: 1, nsec: 0 });
expect(bag.endTime).toEqual({ sec: 3, nsec: 0 });
});

describe("compression", () => {
it("throws if compression scheme is not registered", async () => {
let errorThrown = false;
Expand Down

0 comments on commit 8d295a0

Please sign in to comment.