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

benrr101 / node-taglib-sharp / 51161498

13 Dec 2024 04:24AM UTC coverage: 92.554%. Remained the same
51161498

push

appveyor

benrr101
Merge branch 'release/v6.0.1' into develop

3251 of 4131 branches covered (78.7%)

Branch coverage included in aggregate %.

26753 of 28287 relevant lines covered (94.58%)

471.62 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
    /**
14
     * Renders the provided `box` for output into a file.
15
     * @param box Box to render
16
     * @returns ByteVector Box as rendered for output into a file.
17
     */
18
    public static renderBox(box: Mpeg4Box): ByteVector {
19
        Guards.truthy(box, "box");
×
20

21
        let freeFound = false;
×
22
        const outputVectors: ByteVector[] = [];
×
23

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

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

51
            outputVectors.push(this.renderBox(newPadding));
×
52
        }
53

54

55
        // Handle the box-specific headers
56
        const boxHeaders = box.renderBoxHeaders();
×
57
        if (boxHeaders?.length > 0) {
×
58
            outputVectors.splice(0, 0, ...boxHeaders);
×
59
        }
60

61
        // Adjust the data's header size for the new content, render the header
62
        box.header.dataSize = outputVectors.reduce((accum, current) => accum + current.length, 0);
×
63
        outputVectors.splice(0, 0, box.header.render());
×
64

65
        return ByteVector.concatenate(...outputVectors);
×
66
    }
67
}
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