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

benrr101 / node-taglib-sharp / 46462135

pending completion
46462135

push

appveyor

Benjamin Russell
Merge branch 'release/v5.1.0'

3096 of 3788 branches covered (81.73%)

Branch coverage included in aggregate %.

2171 of 2171 new or added lines in 47 files covered. (100.0%)

25320 of 26463 relevant lines covered (95.68%)

437.0 hits per line

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

86.6
/src/asf/objects/descriptorBase.ts
1
import UuidWrapper from "../../uuidWrapper";
1✔
2
import {ByteVector, StringType} from "../../byteVector";
1✔
3
import {CorruptFileError} from "../../errors";
1✔
4
import {Guards} from "../../utils";
1✔
5

6
/**
7
 * Indicates the type of data stored in a {@link ContentDescriptor} or {@link MetadataDescriptor} object.
8
 */
9
export enum DataType {
1✔
10
    /**
11
     * The descriptor contains Unicode (UTF-16LE) text.
12
     */
13
    Unicode = 0,
1✔
14

15
    /**
16
     * The descriptor contains binary data.
17
     */
18
    Bytes = 1,
1✔
19

20
    /**
21
     * The descriptor contains a boolean value.
22
     */
23
    Bool = 2,
1✔
24

25
    /**
26
     * The descriptor contains a 4-byte DWORD value.
27
     */
28
    DWord = 3,
1✔
29

30
    /**
31
     * The descriptor contains a 8-byte QWORD value.
32
     */
33
    QWord = 4,
1✔
34

35
    /**
36
     * The descriptor contains a 2-byte WORD value.
37
     */
38
    Word = 5,
1✔
39

40
    /**
41
     * The descriptor contains a 16-byte GUID value.
42
     */
43
    Guid = 6
1✔
44
}
45

46
/**
47
 * Type shortcut for all the types a descriptor can contain
48
 */
49
export type DescriptorValue = bigint | boolean | ByteVector | number | string | UuidWrapper;
50

51
/**
52
 * Abstract class that forms the basis of extended content descriptors and metadata library records.
53
 */
54
export abstract class DescriptorBase {
1✔
55
    private readonly _name: string;
56
    private readonly _type: DataType;
57

58
    private readonly _boolValue: boolean;
59
    private readonly _byteValue: ByteVector;
60
    private readonly _dWordValue: number;
61
    private readonly _guidValue: UuidWrapper;
62
    private readonly _qWordValue: bigint;
63
    private readonly _stringValue: string;
64
    private readonly _wordValue: number;
65

66
    protected constructor(name: string, type: DataType, value: DescriptorValue) {
67
        this._name = name;
376✔
68
        this._type = type;
376✔
69

70
        switch (type) {
376✔
71
            case DataType.Word:
376✔
72
                if (typeof(value) !== "number") {
107✔
73
                    throw new Error("Invalid value type for datatype WORD");
7✔
74
                }
75

76
                Guards.ushort(value, "value");
100✔
77
                this._wordValue = value;
97✔
78
                break;
97✔
79
            case DataType.DWord:
80
                if (typeof(value) !== "number") {
22✔
81
                    throw new Error("Invalid value type for datatype DWORD");
7✔
82
                }
83

84
                Guards.uint(value, "value");
15✔
85
                this._dWordValue = value;
12✔
86
                break;
12✔
87
            case DataType.QWord:
88
                if (typeof(value) !== "bigint") {
14✔
89
                    throw new Error("Invalid value type for datatype QWORD");
7✔
90
                }
91

92
                Guards.ulong(value, "value");
7✔
93
                this._qWordValue = value;
5✔
94
                break;
5✔
95
            case DataType.Bool:
96
                if (typeof(value) !== "boolean") {
18✔
97
                    throw new Error("Invalid value type for datatype boolean");
7✔
98
                }
99

100
                this._boolValue = value;
11✔
101
                break;
11✔
102
            case DataType.Unicode:
103
                if (typeof(value) !== "string") {
158✔
104
                    throw new Error("Invalid value type for datatype unicode");
7✔
105
                }
106

107
                this._stringValue = value;
151✔
108
                break;
151✔
109
            case DataType.Bytes:
110
                if (!(value instanceof ByteVector)) {
44✔
111
                    throw new Error("Invalid value type for datatype bytes");
17✔
112
                }
113

114
                this._byteValue = value.toByteVector();
27✔
115
                break;
27✔
116
            case DataType.Guid:
117
                if (!(value instanceof UuidWrapper)) {
12✔
118
                    throw new Error("Invalid value type for datatype GUID");
7✔
119
                }
120

121
                this._guidValue = value;
5✔
122
                break;
5✔
123
            default:
124
                throw new CorruptFileError(`Invalid datatype ${type}`);
1✔
125
        }
126
    }
127

128
    // #region Properties
129

130
    /**
131
     * Gets the name of the current instance.
132
     */
133
    public get name(): string { return this._name; }
490✔
134

135
    /**
136
     * Gets the type of data contained in the current instance.
137
     */
138
    public get type(): DataType { return this._type; }
368✔
139

140
    /**
141
     * Gets the boolean value of the current instance.
142
     * @returns
143
     *     Boolean value of the current instance is returned if {@link type} is
144
     *     {@link DataType.Bool}. `undefined` is returned otherwise.
145
     */
146
    public get boolValue(): boolean { return this._boolValue; }
17✔
147

148
    /**
149
     * Gets the binary contents of the current instance.
150
     * @returns
151
     *     Byte contents of the current instance, if {@link type} is
152
     *     {@link DataType.Bytes}. `undefined` is returned otherwise.
153
     */
154
    public get byteValue(): ByteVector { return this._byteValue; }
31✔
155

156
    /**
157
     * Gets the guid contents of the current instance.
158
     * @returns
159
     *     GUID contents of the current instance, if {@link type} is
160
     *     {@link DataType.Guid}. `undefined` is returned otherwise.
161
     */
162
    public get guidValue(): UuidWrapper { return this._guidValue; }
13✔
163

164
    /**
165
     * Gets the string contents of the current instance.
166
     * @returns
167
     *     String contents of the current instance if {@link type} is
168
     *     {@link DataType.Unicode}. `undefined` is returned otherwise.
169
     */
170
    public get stringValue(): string { return this._stringValue; }
193✔
171

172
    /**
173
     * Gets the 32-bit double word contents of the current instance.
174
     * @returns
175
     *     Double word contents of the current instance, if {@link type} is
176
     *     {@link DataType.DWord}. `undefined` is returned otherwise.
177
     */
178
    public get uintValue(): number { return this._dWordValue; }
21✔
179

180
    /**
181
     * Gets the 64-bit quad word contents of the current instance.
182
     * @returns
183
     *     Quad word contents of the current instance, if {@link type} is
184
     *     {@link DataType.QWord}. `undefined` is returned otherwise.
185
     */
186
    public get ulongValue(): bigint { return this._qWordValue; }
13✔
187

188
    /**
189
     * Gets the 16-bit word contents of the current instance.
190
     * @returns
191
     *     Word contents of the current instance, if {@link type} is
192
     *     {@link DataType.Word}. `undefined` is returned otherwise.
193
     */
194
    public get ushortValue(): number { return this._wordValue; }
25✔
195

196
    public abstract render(): ByteVector;
197

198
    /** @inheritDoc */
199
    public toString(): string {
200
        switch (this._type) {
1✔
201
            case DataType.QWord:
1!
202
                return this._qWordValue.toString();
×
203
            case DataType.DWord:
204
                return this._dWordValue.toString();
×
205
            case DataType.Word:
206
                return this._wordValue.toString();
×
207
            case DataType.Bool:
208
                return this._boolValue.toString();
×
209
            case DataType.Unicode:
210
                return this._stringValue;
1✔
211
            case DataType.Bytes:
212
                return this._byteValue.toString(StringType.UTF16LE);
×
213
            case DataType.Guid:
214
                return this._guidValue.toString();
×
215
        }
216
        return undefined;
×
217
    }
218

219
    // #endregion
220
}
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