• 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

70.37
/src/mpeg/mpegAudioFile.ts
1
import MpegAudioFileSettings from "./mpegAudioFileSettings";
1✔
2
import MpegAudioHeader from "./mpegAudioHeader";
1✔
3
import SandwichFile from "../sandwich/sandwichFile";
1✔
4
import {CorruptFileError} from "../errors";
1✔
5
import {File, ReadStyle} from "../file";
1✔
6
import {IFileAbstraction} from "../fileAbstraction";
7
import {Properties} from "../properties";
1✔
8
import {TagTypes} from "../tag";
1✔
9
import {NumberUtils} from "../utils";
1✔
10

11
/**
12
 * This class extends {@link SandwichFile} to provide tagging and properties support for
13
 * MPEG-1, MPEG-2, and MPEG-2.5 non-containerized audio files.
14
 */
15
export default class MpegAudioFile extends SandwichFile {
1✔
16
    private static readonly DEFAULT_TAG_LOCATION_MAPPING = new Map<TagTypes, () => boolean>([
1✔
17
        [TagTypes.Ape, () => MpegAudioFileSettings.preferApeTagAtFileEnd],
2✔
18
        [TagTypes.Id3v1, () => true],
1✔
19
        [TagTypes.Id3v2, () => MpegAudioFileSettings.preferId3v2TagAtFileEnd]
2✔
20
    ]);
21

22
    private _firstHeader: MpegAudioHeader;
23

24
    public constructor(file: IFileAbstraction|string, propertiesStyle: ReadStyle) {
25
        super(file, propertiesStyle, MpegAudioFile.DEFAULT_TAG_LOCATION_MAPPING, MpegAudioFileSettings.defaultTagTypes);
3✔
26
    }
27

28
    protected readProperties(readStyle: ReadStyle): Properties {
29
        if (!NumberUtils.hasFlag(readStyle, ReadStyle.Average)) {
3!
30
            return undefined;
3✔
31
        }
32

33
        // @TODO: if readStyle is higher than average, scan the entire file to accurately calculate
34
        //    the duration.
35

36
        // Skip if we're not reading the properties
37
        this._firstHeader = MpegAudioHeader.find(this, this.mediaStartPosition, 0x4000);
×
38
        if (!this._firstHeader) {
×
39
            throw new CorruptFileError("MPEG audio header not found");
×
40
        }
41

42
        this._firstHeader.streamLength = this.mediaEndPosition - this.mediaStartPosition;
×
43
        return new Properties(this._firstHeader.durationMilliseconds, [this._firstHeader]);
×
44
    }
45
}
46

47
// /////////////////////////////////////////////////////////////////////////
48
// Register the file type
49
[
1✔
50
    "taglib/mp3",
51
    "audio/x-mp3",
52
    "application/x-id3",
53
    "audio/mpeg",
54
    "audio/x-mpeg",
55
    "audio/x-mpeg-3",
56
    "audio/mpeg3",
57
    "audio/mp3",
58
    "taglib/m2a",
59
    "taglib/mp2",
60
    "taglib/mp1",
61
    "audio/x-mp2",
62
    "audio/x-mp1"
63
].forEach((mt) => File.addFileType(mt, MpegAudioFile));
13✔
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

© 2025 Coveralls, Inc