fix(01-review): WR-08 downloadArchive use shared blobToBase64 helper

This commit is contained in:
2026-05-16 10:25:34 +02:00
parent e9aae09f6d
commit f8a9c10758

View File

@@ -1,5 +1,5 @@
import { Logger } from '../shared/logger';
import { base64ToBlob } from '../shared/binary';
import { base64ToBlob, blobToBase64 } from '../shared/binary';
import type {
Message,
TransferredVideoSegment,
@@ -391,14 +391,12 @@ async function downloadArchive(archiveBlob: Blob) {
logger.log(`Downloading archive: ${filename} (${archiveBlob.size} bytes)`);
// Конвертируем Blob в Data URL (работает в Service Worker)
const arrayBuffer = await archiveBlob.arrayBuffer();
const uint8Array = new Uint8Array(arrayBuffer);
let binary = '';
for (let i = 0; i < uint8Array.length; i++) {
binary += String.fromCharCode(uint8Array[i]);
}
const base64 = btoa(binary);
// WR-08 fix: delegate to the shared `blobToBase64` helper instead of
// re-implementing the same per-byte concat + btoa inline. Keeps the
// wire-format encoding single-source-of-truth (also used by the
// offscreen↔SW port; see src/shared/binary.ts) and ensures any future
// performance work (chunked apply, etc.) propagates to both call sites.
const base64 = await blobToBase64(archiveBlob);
const url = `data:application/zip;base64,${base64}`;
await chrome.downloads.download({