github
421 of 537 branches covered (78.4%)
Branch coverage included in aggregate %.
18 of 128 new or added lines in 4 files covered. (14.06%)
1 existing line in 1 file now uncovered.2064 of 3590 relevant lines covered (57.49%)
33.2 hits per line
|
|
export class COBSDecoderError extends Error { |
1✔ |
|
|
constructor(message?: string) {
|
1✔ |
|
NEW
|
super(message); |
× |
|
NEW
|
this.name = "COBSDecoderError"; |
× |
|
NEW
|
} |
× |
|
|
} |
1✔ |
| 7 |
|
|
| 8 |
|
|
|
|
export function decodeCOBS(data: Array<number>) {
|
1✔ |
|
NEW
|
const output: Array<number> = []
|
× |
|
NEW
|
let i = 0
|
× |
| 12 |
|
|
|
NEW
|
while (i < data.length) {
|
× |
|
NEW
|
const code = data[i]
|
× |
|
NEW
|
if (code === 0 || i + code > data.length + 1) { |
× |
|
NEW
|
throw new COBSDecoderError("Invalid COBS data") |
× |
|
NEW
|
} |
× |
| 18 |
|
|
|
NEW
|
const nextBlockEnd = i + code
|
× |
|
NEW
|
for (let j = i + 1; j < nextBlockEnd && j < data.length; j++) { |
× |
|
NEW
|
output.push(data[j]) |
× |
|
NEW
|
} |
× |
| 23 |
|
|
|
NEW
|
if (code < 0xFF && nextBlockEnd < data.length) { |
× |
|
NEW
|
output.push(0x00)
|
× |
|
NEW
|
} |
× |
| 27 |
|
|
|
NEW
|
i = nextBlockEnd |
× |
|
NEW
|
} |
× |
| 30 |
|
|
|
NEW
|
return Uint8Array.from(output)
|
× |
|
NEW
|
} |
× |