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

benrr101 / node-taglib-sharp / 48387633

28 Oct 2023 05:34AM UTC coverage: 92.442% (+0.5%) from 91.899%
48387633

push

appveyor

web-flow
Merge 6a78b5713 into f0c9477b7

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%)

26753 of 28309 relevant lines covered (94.5%)

422.49 hits per line

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

10.42
/src/mpeg4/mpeg4BoxRenderer.ts
1
import IsoFreeSpaceBox from "./boxes/isoFreeSpaceBox";
1✔
2
import Mpeg4Box from "./boxes/mpeg4Box";
3
import Mpeg4BoxType from "./mpeg4BoxType";
1✔
4
import {ByteVector} from "../byteVector";
1✔
5
import {Guards} from "../utils";
1✔
6

7
/**
8
 * Renderer for {@link Mpeg4Box} objects.
9
 * @remarks Written this way to break a circular dependency from child {@link Mpeg4Box} classes and
10
 *     the root {@link Mpeg4Box} class.
11
 */
12
export default class Mpeg4BoxRenderer {
1✔
13
    public static renderBox(box: Mpeg4Box): ByteVector {
14
        Guards.truthy(box, "box");
×
15

16
        let freeFound = false;
×
17
        const outputVectors: ByteVector[] = [];
×
18

19
        // Write children or data
20
        if (box.hasChildren) {
×
21
            for (const child of box.children) {
×
22
                if (box instanceof IsoFreeSpaceBox) {
×
23
                    freeFound = true;
×
24
                } else {
25
                    outputVectors.push(this.renderBox(child));
×
26
                }
27
            }
28
        } else if (box.data) {
×
29
            // @TODO: If the box generates the data property on get, we should change it to a render method.
30
            outputVectors.push(box.data);
×
31
        }
32

33
        // If there was a free, don't take it away, and let meta be a special case
34
        if (freeFound || ByteVector.equals(box.boxType, Mpeg4BoxType.META)) {
×
35
            const newSizeSoFar = outputVectors.reduce((accum, current) => accum + current.length, 0);
×
36
            const sizeDifference = box.dataSize - newSizeSoFar;
×
37
            let newPadding: IsoFreeSpaceBox;
38
            if (box.header.dataSize !== 0 && sizeDifference >= 8) {
×
39
                // If we have room for free space, add it so we don't have to resize the file
40
                newPadding = IsoFreeSpaceBox.fromPadding(sizeDifference);
×
41
            } else {
42
                // If we're getting bigger, get a lot bigger so we might not have to do this again
43
                newPadding = IsoFreeSpaceBox.fromPadding(2048);
×
44
            }
45

46
            outputVectors.push(this.renderBox(newPadding));
×
47
        }
48

49

50
        // Handle the box-specific headers
51
        const boxHeaders = box.renderBoxHeaders();
×
52
        if (boxHeaders?.length > 0) {
×
53
            outputVectors.splice(0, 0, ...boxHeaders);
×
54
        }
55

56
        // Adjust the data's header size for the new content, render the header
57
        box.header.dataSize = outputVectors.reduce((accum, current) => accum + current.length, 0);
×
58
        outputVectors.splice(0, 0, box.header.render());
×
59

60
        return ByteVector.concatenate(...outputVectors);
×
61
    }
62
}
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