Skip to content

Commit

Permalink
src/jumbf/SuperBox.ts: Replace call to existing deserialization code …
Browse files Browse the repository at this point in the history
…(WIP)

This doesn't work completely, yet, but it already sets the URI field on
super boxes after parsing the box tree.
  • Loading branch information
UlrichEckhardt committed Jul 22, 2024
1 parent 179c79b commit e0e4fc4
Showing 1 changed file with 25 additions and 3 deletions.
28 changes: 25 additions & 3 deletions src/jumbf/SuperBox.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,9 +81,31 @@ export class SuperBox extends Box {
}

public static fromBuffer(buf: Uint8Array): SuperBox {
const box = BoxReader.readFromBuffer(buf, 'self#jumbf=').box;
if (!(box instanceof SuperBox)) throw new Error('Outer box is not a JUMBF super box');
return box;
// eslint-disable-next-line no-constant-condition
if (true) {
const reader = new bin.BufferReader(buf, { endianness: 'big' });
const box = SuperBox.schema.read(reader);

const rootURI = 'self#jumbf=';

SuperBox.applyURI(box, rootURI);

return box;
} else {
const box = BoxReader.readFromBuffer(buf, 'self#jumbf=').box;
if (!(box instanceof SuperBox)) throw new Error('Outer box is not a JUMBF super box');

return box as SuperBox;
}
}

private static applyURI(box: SuperBox, uri: string) {
if (box.descriptionBox!.label) {
box.uri = `${uri}/${box.descriptionBox!.label}`;
}
box.contentBoxes.forEach(subBox => {
if (subBox instanceof SuperBox) SuperBox.applyURI(subBox, box.uri!);
});
}

public parse(buf: Uint8Array, uriPrefix?: string) {
Expand Down

0 comments on commit e0e4fc4

Please sign in to comment.