mirror of
https://github.com/morluto/rea.git
synced 2026-12-06 23:09:34 +00:00
refactor(firmware): share sparse-image chunk accounting (#16877)
This commit is contained in:
1 parent
fdd1afae54
commit
6cd4770f0b
1 file changed
+20
-30
@@ -539,43 +539,33 @@ export class AndroidSparseImageAccumulator {
|
||||
this.#walked += 1;
|
||||
this.#blocks += BigInt(chunk.outputBytes) / BigInt(this.#header.blockSize);
|
||||
this.#end += chunk.totalSize;
|
||||
if (chunk.kind === "raw") {
|
||||
this.#counts.raw += 1;
|
||||
this.#covered.raw += chunk.outputBytes;
|
||||
if (chunk.outputBytes > 0)
|
||||
this.#runs.push({
|
||||
kind: "raw",
|
||||
offset: chunk.dataOffset,
|
||||
length: chunk.outputBytes,
|
||||
});
|
||||
} else if (chunk.kind === "fill") {
|
||||
this.#counts.fill += 1;
|
||||
this.#covered.fill += chunk.outputBytes;
|
||||
const pattern = Buffer.from(chunk.pattern).toString("hex");
|
||||
if (!this.#fillPatterns.has(pattern)) {
|
||||
if (this.#fillPatterns.size < ANDROID_SPARSE_LISTED_CHUNKS)
|
||||
this.#fillPatterns.add(pattern);
|
||||
else this.#fillPatternsOmitted = true;
|
||||
}
|
||||
if (chunk.outputBytes > 0)
|
||||
this.#runs.push({
|
||||
kind: "fill",
|
||||
pattern: chunk.pattern,
|
||||
length: chunk.outputBytes,
|
||||
});
|
||||
} else if (chunk.kind === "dont-care") {
|
||||
this.#counts.dontCare += 1;
|
||||
this.#covered.dontCare += chunk.outputBytes;
|
||||
if (chunk.outputBytes > 0)
|
||||
this.#runs.push({ kind: "dont-care", length: chunk.outputBytes });
|
||||
} else {
|
||||
if (chunk.kind === "crc32") {
|
||||
this.#counts.crc32 += 1;
|
||||
if (this.#crc32Chunks.length < ANDROID_SPARSE_LISTED_CHUNKS)
|
||||
this.#crc32Chunks.push({
|
||||
fileOffset: chunk.fileOffset,
|
||||
value: chunk.value,
|
||||
});
|
||||
return;
|
||||
}
|
||||
const key = chunk.kind === "dont-care" ? "dontCare" : chunk.kind;
|
||||
const length = chunk.outputBytes;
|
||||
this.#counts[key] += 1;
|
||||
this.#covered[key] += length;
|
||||
if (chunk.kind === "fill") {
|
||||
const pattern = Buffer.from(chunk.pattern).toString("hex");
|
||||
if (!this.#fillPatterns.has(pattern)) {
|
||||
if (this.#fillPatterns.size < ANDROID_SPARSE_LISTED_CHUNKS)
|
||||
this.#fillPatterns.add(pattern);
|
||||
else this.#fillPatternsOmitted = true;
|
||||
}
|
||||
}
|
||||
if (length <= 0) return;
|
||||
if (chunk.kind === "raw")
|
||||
this.#runs.push({ kind: "raw", offset: chunk.dataOffset, length });
|
||||
else if (chunk.kind === "fill")
|
||||
this.#runs.push({ kind: "fill", pattern: chunk.pattern, length });
|
||||
else this.#runs.push({ kind: "dont-care", length });
|
||||
}
|
||||
|
||||
/** Check the walked chunks against the header and build the image. */
|
||||
|
||||
Reference in new issue
Block a user