chore: snapshot main sync
This commit is contained in:
@@ -141,8 +141,10 @@ export function trimCapture(captureJson: string | null, sizeKB: number): string
|
||||
if (!captureJson) return null;
|
||||
const sizeBytes = Buffer.byteLength(captureJson, 'utf8');
|
||||
if (sizeBytes <= sizeKB * 1024) return captureJson;
|
||||
// Trim the capture to fit within the cap.
|
||||
return captureJson.slice(0, Math.floor(sizeKB * 1024));
|
||||
// Trim by BYTES, not JS chars: a char-index slice can split a multi-byte
|
||||
// codepoint and emit invalid UTF-8 (DB write error / corruption). Buffer
|
||||
// subarray + toString('utf8') truncates at the last whole codepoint.
|
||||
return Buffer.from(captureJson, 'utf8').subarray(0, Math.floor(sizeKB * 1024)).toString('utf8');
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user