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

discoveryjs / scan-git / 11604860525

31 Oct 2024 02:10AM UTC coverage: 86.986% (-0.9%) from 87.86%
11604860525

push

github

lahmatiy
Bump dev deps

358 of 401 branches covered (89.28%)

Branch coverage included in aggregate %.

2329 of 2688 relevant lines covered (86.64%)

265.31 hits per line

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

85.19
/src/utils/buffer.ts
1
// https://git-scm.com/docs/pack-format
1✔
2
// offset encoding: n bytes with MSB set in all but the last one.
1✔
3
// The offset is then the number constructed by
1✔
4
// concatenating the lower 7 bit of each byte, and
1✔
5
// for n >= 2 adding 2^7 + 2^14 + ... + 2^(7*(n-1))
1✔
6
// to the result.
1✔
7
export function readEncodedOffset(reader: BufferCursor) {
1✔
8
    let result = -1;
1,497✔
9
    let byte = 0;
1,497✔
10

1,497✔
11
    do {
1,497✔
12
        byte = reader.readUInt8();
3,052✔
13

3,052✔
14
        // Note: An encoded offset can be greater than int32, so we can't use binary ops
3,052✔
15
        // for the result to avoid an overflow. As an alternative a BigInt for the result
3,052✔
16
        // might be used but it involves unwanted BigInt<->Number conversions.
3,052✔
17
        //
3,052✔
18
        // The expression is equivalent to:
3,052✔
19
        //   result = ((result + 1) << 7) | (byte & 0b0111111)
3,052✔
20
        result = (result + 1) * 128 + (byte & 0b01111111);
3,052✔
21
    } while (byte & 0b10000000);
1,497✔
22

1,497✔
23
    return result;
1,497✔
24
}
1,497✔
25

1✔
26
export function readVarIntLE(reader: BufferCursor) {
1✔
27
    let result = 0;
5,507✔
28
    let shift = 0;
5,507✔
29
    let byte = 0;
5,507✔
30

5,507✔
31
    do {
5,507✔
32
        byte = reader.readUInt8();
11,133✔
33
        result |= (byte & 0b01111111) << shift;
11,133✔
34
        shift += 7;
11,133✔
35
    } while (byte & 0b10000000);
5,507✔
36

5,507✔
37
    return result;
5,507✔
38
}
5,507✔
39

1✔
40
export class BufferCursor {
1✔
41
    offset = 0;
1,542✔
42
    constructor(public buffer: Buffer) {}
1,542✔
43

1,542✔
44
    get eof() {
1,542✔
45
        return this.offset >= this.buffer.length;
100✔
46
    }
100✔
47
    get bytesLeft() {
1,542✔
48
        return this.buffer.byteLength - this.offset;
3,956✔
49
    }
3,956✔
50

1,542✔
51
    slice(length: number) {
1,542✔
52
        return this.buffer.slice(this.offset, (this.offset += length));
1,475✔
53
    }
1,475✔
54

1,542✔
55
    toString(enc: BufferEncoding, length: number) {
1,542✔
56
        return this.buffer.toString(enc, this.offset, (this.offset += length));
×
57
    }
×
58

1,542✔
59
    write(value: string, length: number, enc?: BufferEncoding) {
1,542✔
60
        const bytesWritten = this.buffer.write(value, this.offset, length, enc);
×
61
        this.offset += bytesWritten;
×
62
        return bytesWritten;
×
63
    }
×
64

1,542✔
65
    copyFrom(source: Buffer, sourceStart?: number, sourceEnd?: number) {
1,542✔
66
        const copiedBytes = source.copy(this.buffer, this.offset, sourceStart, sourceEnd);
×
67

×
68
        this.offset += copiedBytes;
×
69

×
70
        return copiedBytes;
×
71
    }
×
72

1,542✔
73
    copyTo(target: Buffer, targetStart = 0, length = this.bytesLeft) {
1,542✔
74
        const copiedBytes = this.buffer.copy(
30✔
75
            target,
30✔
76
            targetStart,
30✔
77
            this.offset,
30✔
78
            this.offset + length
30✔
79
        );
30✔
80

30✔
81
        this.offset += copiedBytes;
30✔
82

30✔
83
        return copiedBytes;
30✔
84
    }
30✔
85

1,542✔
86
    readUInt8() {
1,542✔
87
        const r = this.buffer.readUInt8(this.offset);
14,385✔
88
        this.offset += 1;
14,385✔
89
        return r;
14,385✔
90
    }
14,385✔
91

1,542✔
92
    readUInt32BE() {
1,542✔
93
        const r = this.buffer.readUInt32BE(this.offset);
×
94
        this.offset += 4;
×
95
        return r;
×
96
    }
×
97
}
1,542✔
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