• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

benrr101 / node-taglib-sharp / 48257345

12 Oct 2023 04:06AM UTC coverage: 92.315% (+0.4%) from 91.944%
48257345

push

appveyor

benrr101
Performer roles (bug fixed), genres

3226 of 4153 branches covered (0.0%)

Branch coverage included in aggregate %.

94 of 94 new or added lines in 2 files covered. (100.0%)

27069 of 28664 relevant lines covered (94.44%)

417.21 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

18.25
/src/mpeg4/mpeg4BoxFactory.ts
1
import AppleAdditionalInfoBox from "./boxes/appleAdditionalInfoBox";
1✔
2
import AppleAnnotationBox from "./boxes/appleAnnotationBox";
1✔
3
import AppleElementaryStreamDescriptor from "./boxes/appleElementaryStreamDescriptor";
1✔
4
import AppleItemListBox from "./boxes/appleItemListBox";
1✔
5
import IsoAudioSampleEntry from "./boxes/isoAudioSampleEntry";
1✔
6
import IsoChunkLargeOffsetBox from "./boxes/isoChunkLargeOffsetBox";
1✔
7
import IsoChunkOffsetBox from "./boxes/isoChunkOffsetBox";
1✔
8
import IsoFreeSpaceBox from "./boxes/isoFreeSpaceBox";
1✔
9
import IsoHandlerBox from "./boxes/isoHandlerBox";
1✔
10
import IsoMetaBox from "./boxes/isoMetaBox";
1✔
11
import IsoMovieHeaderBox from "./boxes/isoMovieHeaderBox";
1✔
12
import IsoSampleDescriptionBox from "./boxes/isoSampleDescriptionBox";
1✔
13
import IsoSampleTableBox from "./boxes/isoSampleTableBox";
1✔
14
import IsoUnknownSampleEntry from "./boxes/isoUnknownSampleEntry";
1✔
15
import IsoUserDataBox from "./boxes/isoUserDataBox";
1✔
16
import IsoVisualSampleEntry from "./boxes/isoVisualSampleEntry";
1✔
17
import Mpeg4Box from "./boxes/mpeg4Box";
18
import Mpeg4BoxHeader from "./mpeg4BoxHeader";
1✔
19
import Mpeg4BoxType from "./mpeg4BoxType";
1✔
20
import Mpeg4HandlerType from "./mpeg4HandlerType";
1✔
21
import TextBox from "./boxes/textBox";
1✔
22
import UnknownBox from "./boxes/unknownBox";
1✔
23
import UrlBox from "./boxes/urlBox";
1✔
24
import {AppleDataBox} from "./boxes/appleDataBox";
1✔
25
import {ByteVector} from "../byteVector";
1✔
26
import {File} from "../file";
27

28
/**
29
 * This class provides support for reading boxes from a file.
30
 */
31
export default class Mpeg4BoxFactory {
1✔
32
    /**
33
     * Creates a box by reading it from a file given its header, parent header, handler, and index in its parent.
34
     * @param file A {@link File} object containing the file to read from.
35
     * @param header A {@link Mpeg4BoxHeader} object containing the header of the box to create.
36
     * @param handlerType? Type of the handler box containing the handler that applies to the new box.
37
     * @param parentHeader? A
38
     * @returns A newly created {@link Mpeg4Box} object.
39
     */
40
    public static createBox(
41
        file: File,
42
        header: Mpeg4BoxHeader,
43
        handlerType?: ByteVector,
44
        parentHeader?: Mpeg4BoxHeader,
45
    ): Mpeg4Box {
46
        // Standard items...
47
        const type = header.boxType;
×
48

49
        if (ByteVector.equals(type, Mpeg4BoxType.MVHD)) {
×
50
            return IsoMovieHeaderBox.fromHeaderFileAndHandler(header, file, handlerType);
×
51
        }
52
        else if (ByteVector.equals(type, Mpeg4BoxType.STBL))
×
53
        {
54
            const box = IsoSampleTableBox.fromFile(file, header, handlerType);
×
55
            this.loadChildren(file, box);
×
56
            return box;
×
57
        }
58
        else if (ByteVector.equals(type, Mpeg4BoxType.STSD))
×
59
        {
60
            const box = IsoSampleDescriptionBox.fromFile(file, header, handlerType);
×
61
            this.loadSampleDescriptors(file, box);
×
62
            return box;
×
63
        }
64
        else if (ByteVector.equals(type, Mpeg4BoxType.STCO))
×
65
        {
66
            return IsoChunkOffsetBox.fromHeaderFileAndHandler(header, file, handlerType);
×
67
        }
68
        else if (ByteVector.equals(type, Mpeg4BoxType.CO64))
×
69
        {
70
            return IsoChunkLargeOffsetBox.fromHeaderFileAndHandler(header, file, handlerType);
×
71
        }
72
        else if (ByteVector.equals(type, Mpeg4BoxType.HDLR))
×
73
        {
74
            return IsoHandlerBox.fromHeaderFileAndHandler(header, file, handlerType);
×
75
        }
76
        else if (ByteVector.equals(type, Mpeg4BoxType.UDTA))
×
77
        {
78
            const box = IsoUserDataBox.fromFile(file, header, handlerType);
×
79
            this.loadChildren(file, box);
×
80
            return box;
×
81
        }
82
        else if (ByteVector.equals(type, Mpeg4BoxType.META))
×
83
        {
84
            const box = IsoMetaBox.fromFile(file, header, handlerType);
×
85
            this.loadChildren(file, box);
×
86
            return box;
×
87
        }
88
        else if (ByteVector.equals(type, Mpeg4BoxType.ILST))
×
89
        {
90
            const box = AppleItemListBox.fromFile(file, header, handlerType);
×
91
            this.loadChildren(file, box);
×
92
            return box;
×
93
        }
94
        else if (ByteVector.equals(type, Mpeg4BoxType.DATA))
×
95
        {
96
            return AppleDataBox.fromHeaderFileAndHandler(header, file, handlerType);
×
97
        }
98
        else if (ByteVector.equals(type, Mpeg4BoxType.ESDS))
×
99
        {
100
            return AppleElementaryStreamDescriptor.fromHeaderFileAndHandler(header, file, handlerType);
×
101
        }
102
        else if (ByteVector.equals(type, Mpeg4BoxType.FREE) || ByteVector.equals(type, Mpeg4BoxType.SKIP))
×
103
        {
104
            return IsoFreeSpaceBox.fromHeaderFileAndHandler(header, file, handlerType);
×
105
        }
106
        else if (ByteVector.equals(type, Mpeg4BoxType.MEAN) || ByteVector.equals(type, Mpeg4BoxType.NAME))
×
107
        {
108
            return AppleAdditionalInfoBox.fromHeaderFileAndHandler(header, file, handlerType);
×
109
        }
110

111
        // If we still don't have a tag, and we're inside an ItemListBox, load the box as an
112
        // AnnotationBox (Apple tag item).
113
        if (ByteVector.equals(parentHeader.boxType, Mpeg4BoxType.ILST)) {
×
114
            const box = AppleAnnotationBox.fromFile(file, header, handlerType);
×
115
            this.loadChildren(file, box);
×
116
            return box;
×
117
        }
118

119
        // Nothing good. Go generic.
120
        return UnknownBox.fromHeaderFileAndHandler(header, file, handlerType);
×
121
    }
122

123
    private static loadSampleDescriptors(file: File, box: IsoSampleDescriptionBox): void {
124
        let position = box.dataPosition
×
125
        for (let i = 0; i < box.entryCount; i++) {
×
126
            const header = Mpeg4BoxHeader.fromFileAndPosition(file, position);
×
127
            let child: Mpeg4Box;
128

129
            // I know this isn't the right formatting, but it is damn near unreadable without some spacing
130
            if (ByteVector.equals(box.handlerType, Mpeg4HandlerType.SOUN))
×
131
            {
132
                child = IsoAudioSampleEntry.fromFile(file, header, box.handlerType);
×
133
                this.loadChildren(file, child);
×
134
            }
135
            else if (ByteVector.equals(box.handlerType, Mpeg4HandlerType.VIDE))
×
136
            {
137
                child = IsoVisualSampleEntry.fromHeaderFileAndHandler(header, file, box.handlerType);
×
138
            }
139
            else if (ByteVector.equals(box.handlerType, Mpeg4HandlerType.ALIS))
×
140
            {
141
                if (ByteVector.equals(header.boxType, Mpeg4BoxType.TEXT))
×
142
                {
143
                    child = TextBox.fromHeaderFileAndHandler(header, file, box.handlerType);
×
144
                }
145
                else if (ByteVector.equals(header.boxType, Mpeg4BoxType.URL))
×
146
                {
147
                    child = UrlBox.fromHeaderFileAndHandler(header, file, box.handlerType);
×
148
                }
149
                else
150
                {
151
                    // This could be anything, so just parse it.
152
                    child = UnknownBox.fromHeaderFileAndHandler(header, file, box.handlerType);
×
153
                }
154
            }
155
            else
156
            {
157
                child = IsoUnknownSampleEntry.fromHeaderFileAndHandler(header, file, box.handlerType);
×
158
            }
159

160
            box.addChild(child);
×
161
            position += child.size;
×
162
        }
163
    }
164

165
    private static loadChildren(file: File, box: Mpeg4Box): void {
166
        let position = box.dataPosition;
×
167
        const end = position + box.dataSize;
×
168

169
        while (position < end) {
×
170
            const header = Mpeg4BoxHeader.fromFileAndPosition(file, position);
×
171
            const child = this.createBox(file, header, box.handlerType, box.header);
×
172

173
            if (child.size === 0) {
×
174
                break;
×
175
            }
176

177
            box.addChild(child);
×
178
            position += child.size;
×
179
        }
180
    }
181
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc