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

benrr101 / node-taglib-sharp / 48389652

28 Oct 2023 06:22PM UTC coverage: 92.443% (+0.5%) from 91.9%
48389652

push

appveyor

web-flow
MPEG4 Cleanup (#88)

* Round one

* Round 2

* Fixing up mpeg4box file

* Fix names of box types to match style

* Fix names of box types to match style

* Separate boxes into separate files ... not working yet.

* Decomposing handler type to a bytevector. This is clumsy but will be cleaned up shortly

* Moving rendering to a utility class. Fixes cyclic dependencies

* Adding stuff to index and moving things around to let tests run

* Fixing iso handler box that was broken

* Public fields to properties

* Removing redundant variable typing

* Removing redundant casts

* Removing child factory from isoAudioSampleEntry.ts

* Removing child factory from appleAnnotationBox.ts

* Removing child factory from appleItemListBox.ts and isoMetaBox.ts

* Removing child factory from isoSampleDescriptionBox.ts

* Removing child factory from isoSampleTableBox.ts and isoUserDataBox.ts

* Child factories have been outlawed

* Introduce a handler type class

* Simplify the mpeg4boxtype class

* handler types in a different class

* Rewrite the get* methods

* Some tests

* Single itunes tag tests

* Performer roles (bug fixed), genres

* 99% coverage of appletag

* Pretty much the last cleanup I want to do before another release cycle.

* Leaving a todo

* Ok two more tweaks

3250 of 4147 branches covered (0.0%)

Branch coverage included in aggregate %.

1763 of 1763 new or added lines in 39 files covered. (100.0%)

26757 of 28313 relevant lines covered (94.5%)

422.43 hits per line

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

42.42
/src/mpeg4/boxes/isoHandlerBox.ts
1
import FullBox from "./fullBox";
1✔
2
import Mpeg4BoxHeader from "../mpeg4BoxHeader";
3
import Mpeg4BoxType from "../mpeg4BoxType";
1✔
4
import {ByteVector, StringType} from "../../byteVector";
1✔
5
import {File} from "../../file";
6
import {Guards} from "../../utils";
1✔
7

8
/**
9
 * This class extends @see FullBox to provide an implementation of a ISO/IEC 14496-12 FullBox.
10
 */
11
export default class IsoHandlerBox extends FullBox {
1✔
12
    private _dataHandlerType: ByteVector;
13
    private _name: string;
14

15
    // #region Constructors
16

17
    /**
18
     * Private constructor to force construction via static functions.
19
     */
20
    private constructor() {
21
        super();
113✔
22
    }
23

24
    /**
25
     * Constructs and initializes a new instance of @see IsoHandlerBox with a provided header and h
26
     * handler by reading the contents from a specified file.
27
     * @param header A @see Mpeg4BoxHeader object containing the header to use for the new instance.
28
     * @param file A @see File object to read the contents of the box from.
29
     * @param handlerType Type of the handler box object containing the handler that applies to the
30
     *     new instance, or undefined if no handler applies.
31
     * @returns A new instance of @see IsoHandlerBox
32
     */
33
    public static fromFile(header: Mpeg4BoxHeader, file: File, handlerType: ByteVector): IsoHandlerBox {
34
                const instance = new IsoHandlerBox();
×
35
        instance.initializeFromHeaderFileAndHandler(header, file, handlerType);
×
36

37
        file.seek(instance.dataPosition + 4);
×
38
        const boxData = file.readBlock(instance.dataSize - 4);
×
39
        instance._dataHandlerType = boxData.subarray(0, 4);
×
40

41
        let end = boxData.offsetFind(ByteVector.fromByte(0), 16);
×
42
        if (end < 16) {
×
43
            end = boxData.length;
×
44
        }
45

46
        instance._name = end > 16
×
47
            ? boxData.subarray(16, end - 16).toString(StringType.UTF8)
×
48
            : "";
49

50
        return instance;
×
51
    }
52

53
    /**
54
     * Constructs and initializes a new instance of @see IsoHandlerBox with a specified type and name.
55
     * @param handlerType A @see ByteVector object specifying a 4 byte handler type.
56
     * @param name An object specifying the handler name.
57
     * @returns A new instance of @see IsoHandlerBox
58
     */
59
    public static fromHandlerTypeAndHandlerName(handlerType: ByteVector, name: string): IsoHandlerBox {
60
        Guards.truthy(handlerType, "handlerType");
113✔
61
        if (handlerType.length < 4) {
113!
62
            throw new Error("The handler type must be four bytes long.");
×
63
        }
64

65
        const instance = new IsoHandlerBox();
113✔
66
        instance.initializeFromTypeVersionAndFlags(Mpeg4BoxType.HDLR, 0, 0);
113✔
67
        instance._dataHandlerType = handlerType.subarray(0, 4);
113✔
68
        instance._name = name;
113✔
69

70
        return instance;
113✔
71
    }
72

73
    // #endregion
74

75
    /**
76
     * Gets the data contained in the current instance.
77
     */
78
    public get data(): ByteVector {
79
        return ByteVector.concatenate(
×
80
            ByteVector.fromSize(4),
81
            this.dataHandlerType,
82
            ByteVector.fromSize(12),
83
            ByteVector.fromString(this.name, StringType.UTF8),
84
            ByteVector.fromSize(2)
85
        );
86
    }
87

88
    /**
89
     * Gets the handler type as described in the data of the current instance.
90
     */
91
    public get dataHandlerType(): ByteVector { return this._dataHandlerType; }
×
92

93
    /**
94
     * Gets the name of the current instance.
95
     */
96
    public get name(): string { return this._name; }
×
97
}
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