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

benrr101 / node-taglib-sharp / 47997490

10 Sep 2023 05:11AM UTC coverage: 91.944% (-0.05%) from 91.99%
47997490

push

appveyor

benrr101
Child factories have been outlawed

3268 of 4226 branches covered (0.0%)

Branch coverage included in aggregate %.

8 of 8 new or added lines in 3 files covered. (100.0%)

26658 of 28322 relevant lines covered (94.12%)

411.38 hits per line

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

17.65
/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 TextBox from "./boxes/textBox";
1✔
21
import UnknownBox from "./boxes/unknownBox";
1✔
22
import UrlBox from "./boxes/urlBox";
1✔
23
import {AppleDataBox} from "./boxes/appleDataBox";
1✔
24
import {ByteVector} from "../byteVector";
1✔
25
import {File} from "../file";
26

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

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

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

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

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

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

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

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

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

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

176
            box.addChild(child);
×
177
            position += child.size;
×
178
        }
179
    }
180
}
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