• 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

92.31
/src/asf/objects/filePropertiesObject.ts
1
import BaseObject from "./baseObject";
1✔
2
import ReadWriteUtils from "../readWriteUtils";
1✔
3
import UuidWrapper from "../../uuidWrapper";
4
import {ByteVector} from "../../byteVector";
1✔
5
import {Guids, ObjectType} from "../constants";
1✔
6
import {CorruptFileError} from "../../errors";
1✔
7
import {File} from "../../file";
8
import {NumberUtils} from "../../utils";
1✔
9

10
/**
11
 * Flags that are set on a {@link FilePropertiesObject}. See {@link FilePropertiesObject.flags} for
12
 * more details.
13
 */
14
export enum FilePropertiesFlags {
1✔
15
    /**
16
     * The file is in the process of being created.
17
     */
18
    Broadcast = 0x01,
1✔
19

20
    /**
21
     * The file is seekable.
22
     */
23
    Seekable = 0x02
1✔
24
}
25

26
/**
27
 * Extends {@link BaseObject} to provide a representation of an ASF file properties object. The
28
 * file properties object defines the global characteristics of the combined digital media streams
29
 * found within the Data object.
30
 */
31
export default class FilePropertiesObject extends BaseObject {
1✔
32
    private static readonly FILE_TIME_TO_UNIX_EPOCH = BigInt(116444736000000000);
1✔
33

34
    // #region Member Variables
35

36
    private _creationDateTicks: bigint;
37
    private _dataPacketsCount: bigint;
38
    private _fileId: UuidWrapper;
39
    private _fileSize: bigint;
40
    private _flags: number;
41
    private _maximumBitrate: number;
42
    private _maximumDataPacketSize: number;
43
    private _minimumDataPacketSize: number;
44
    private _playDurationTicks: bigint;
45
    private _prerollMilliseconds: bigint;
46
    private _sendDurationTicks: bigint;
47

48
    // #endregion
49

50
    // #region Constructors
51

52
    private constructor() {
53
        super();
12✔
54
    }
55

56
    /**
57
     * Constructs a new instance by reading from a file.
58
     * @param file File to read the file properties object from
59
     * @param position Offset into the file where the object begins
60
     */
61
    public static fromFile(file: File, position: number): FilePropertiesObject {
62
        const instance = new FilePropertiesObject();
12✔
63
        instance.initializeFromFile(file, position);
12✔
64

65
        if (!instance.guid.equals(Guids.ASF_FILE_PROPERTIES_OBJECT)) {
3!
66
            throw new CorruptFileError("Object GUID is not the expected file properties object GUID");
×
67
        }
68

69
        if (instance.originalSize < 104) {
3!
70
            throw new CorruptFileError("Object size too small for file properties object");
×
71
        }
72

73
        instance._fileId = ReadWriteUtils.readGuid(file);
3✔
74
        instance._fileSize = ReadWriteUtils.readQWord(file);
3✔
75
        instance._creationDateTicks = ReadWriteUtils.readQWord(file);
3✔
76
        instance._dataPacketsCount = ReadWriteUtils.readQWord(file);
3✔
77
        instance._playDurationTicks = ReadWriteUtils.readQWord(file);
3✔
78
        instance._sendDurationTicks = ReadWriteUtils.readQWord(file);
3✔
79
        instance._prerollMilliseconds = ReadWriteUtils.readQWord(file);
3✔
80
        instance._flags = ReadWriteUtils.readDWord(file);
3✔
81
        instance._minimumDataPacketSize = ReadWriteUtils.readDWord(file);
3✔
82
        instance._maximumDataPacketSize = ReadWriteUtils.readDWord(file);
3✔
83
        instance._maximumBitrate = ReadWriteUtils.readDWord(file);
3✔
84

85
        return instance;
3✔
86
    }
87

88
    // #endregion
89

90
    // #region Properties
91

92
    /**
93
     * Gets the creation date of the file described by the current instance.
94
     */
95
    public get creationDate(): Date {
96
        // Creation date is in ticks from 1/1/1601 00:00:00, JS Date is in milliseconds from
97
        // 1/1/1970 00:00:00.
98
        const unixEpochTicks = this._creationDateTicks - FilePropertiesObject.FILE_TIME_TO_UNIX_EPOCH;
1✔
99
        const unixEpochMilli = NumberUtils.ticksToMilli(unixEpochTicks);
1✔
100
        return new Date(unixEpochMilli);
1✔
101
    }
102

103
    /**
104
     * Gets the number of packets in the data section of the file represented by the current
105
     * instance.
106
     */
107
    public get dataPacketsCount(): bigint { return this._dataPacketsCount; }
1✔
108

109
    /**
110
     * Gets the GUID for the file described by the current instance.
111
     */
112
    public get fileId(): UuidWrapper { return this._fileId; }
1✔
113

114
    /**
115
     * Gets the total size of the file described by the current instance in bytes.
116
     */
117
    public get fileSize(): bigint { return this._fileSize; }
1✔
118

119
    /**
120
     * Gets whether the file described by the current instance is broadcast or seekable.
121
     * @remarks
122
     *     This attribute applies to presentation descriptors for ASF content. The value is a
123
     *     bitwise OR of the flags in {@link FilePropertiesFlags}.
124
     *     * If {@link FilePropertiesFlags.Broadcast} is set, the following properties are not
125
     *       valid
126
     *       * {@link fileId}
127
     *       * {@link creationDate}
128
     *       * {@link dataPacketsCount}
129
     *       * {@link playDurationMilliseconds}
130
     *       * {@link sendDurationMilliseconds}
131
     *       * {@link maximumDataPacketSize} and {@link minimumDataPacketSize} are set to the
132
     *         actual packet size
133
     *     * If {@link FilePropertiesFlags.Seekable} is set, an audio stream is present and the
134
     *       {@link maximumDataPacketSize} and {@link minimumDataPacketSize} are set to the same
135
     *       size. It can also be seekable if the file has an audio stream and a video stream with
136
     *       a matching simple index object.
137
     */
138
    public get flags(): number { return this._flags; }
1✔
139

140
    /**
141
     * Gets the maximum instantaneous bit rate, in bits per second, for the file described by the
142
     * current instance.
143
     */
144
    public get maximumBitrate(): number { return this._maximumBitrate; }
1✔
145

146
    /**
147
     * Gets the maximum packet size, in bytes, for the file described by the current instance.
148
     */
149
    public get maximumDataPacketSize(): number { return this._maximumDataPacketSize; }
1✔
150

151
    /**
152
     * Gets the minimum packet size, in bytes, for the file described by the current instance.
153
     */
154
    public get minimumDataPacketSize(): number { return this._minimumDataPacketSize; }
1✔
155

156
    /** @inheritDoc */
157
    public get objectType(): ObjectType { return ObjectType.FilePropertiesObject; }
2✔
158

159
    /**
160
     * Gets the amount of time, in milliseconds, to buffer data before playing the file described
161
     * by the current instance.
162
     */
163
    public get prerollMilliseconds(): number { return Number(this._prerollMilliseconds); }
2✔
164

165
    /**
166
     * Get the time needed to play the file described by the current instance in milliseconds.
167
     */
168
    public get playDurationMilliseconds(): number { return NumberUtils.ticksToMilli(this._playDurationTicks); }
2✔
169

170
    /**
171
     * Get the time needed to send the file described by the current instance in milliseconds. A
172
     * packet's "send time" is the time when the packet should be delivered over the network, it is
173
     * not the presentation of the packet.
174
     */
175
    public get sendDurationMilliseconds(): number { return NumberUtils.ticksToMilli(this._sendDurationTicks); }
1✔
176

177
    // #endregion
178

179
    /** @inheritDoc */
180
    public render(): ByteVector {
181
        const output = ByteVector.concatenate(
1✔
182
            this._fileId.toBytes(),
183
            ReadWriteUtils.renderQWord(this._fileSize),
184
            ReadWriteUtils.renderQWord(this._creationDateTicks),
185
            ReadWriteUtils.renderQWord(this._dataPacketsCount),
186
            ReadWriteUtils.renderQWord(this._playDurationTicks),
187
            ReadWriteUtils.renderQWord(this._sendDurationTicks),
188
            ReadWriteUtils.renderQWord(this._prerollMilliseconds),
189
            ReadWriteUtils.renderDWord(this._flags),
190
            ReadWriteUtils.renderDWord(this._minimumDataPacketSize),
191
            ReadWriteUtils.renderDWord(this._maximumDataPacketSize),
192
            ReadWriteUtils.renderDWord(this._maximumBitrate)
193
        );
194
        return super.renderInternal(output);
1✔
195
    }
196

197

198
}
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