Skip to content

Commit

Permalink
iinfBox.parse: refactor instanceof to check for type
Browse files Browse the repository at this point in the history
before
- in iinfBox.parse we would check if result of parseOneBox is instanceof infeBox
- this would fail in case BoxRegistry does not have infeBox, in which case  generic Box would be created with Box.type = 'infe'

after
- cast result of parseOneBox to BoxKind
- check if box.type === 'infe'
  • Loading branch information
bigmistqke committed Dec 2, 2024
1 parent 5d48d74 commit cc3d9fd
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions src/boxes/iinf.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { infeBox } from '#/boxes/infe';
import type { MultiBufferStream } from '#/buffer';
import { OK } from '#/constants';
import { Log } from '#/log';
import type { BoxKind } from '@types';

export class iinfBox extends Box {
version: number;
Expand All @@ -26,9 +27,9 @@ export class iinfBox extends Box {
for (let i = 0; i < this.entry_count; i++) {
const ret = parseOneBox(stream, false, this.size - (stream.getPosition() - this.start));
if (ret.code === OK) {
// NEEDS REVIEW: this was `ret.box.type == 'infe'` before.
if (ret.box instanceof infeBox) {
this.item_infos[i] = ret.box;
const box = ret.box as BoxKind;
if (box.type === 'infe') {
this.item_infos[i] = box;
} else {
Log.error('BoxParser', "Expected 'infe' box, got " + ret.box.type);
}
Expand Down

0 comments on commit cc3d9fd

Please sign in to comment.