Save uncommitted changes
Build / Lint & Test (push) Successful in 26s

This commit is contained in:
PickleRick committed 2026-09-21 22:57:38 +02:00
1 parent 68166ad7eb
commit b85759e27c
2 files changed
+13 -5

No files matched your search

+11 -5
View File
@@ -35,7 +35,7 @@ const copyWithProgress = async ({
const copyOnceWithStream = () => new Promise((resolve, reject) => {
const startMs = Date.now();
let copiedBytes = 0;
let nextProgressPercent = 0;
let lastReportedPercent = -1;
const rd = fs.createReadStream(source, { highWaterMark: bufferSize });
const wr = fs.createWriteStream(destination, { highWaterMark: bufferSize });
let settled = false;
@@ -56,7 +56,7 @@ const copyWithProgress = async ({
rd.on('data', (chunk) => {
copiedBytes += chunk.length;
const percent = sourceSize === 0 ? 100 : Math.floor((copiedBytes / sourceSize) * 100);
if (percent < nextProgressPercent) return;
if (percent <= lastReportedPercent || percent >= 100) return;
const elapsedSeconds = Math.max((Date.now() - startMs) / 1000, 0.1);
report(
percent,
@@ -64,7 +64,7 @@ const copyWithProgress = async ({
+ `(${(copiedBytes / 1024 / 1024).toFixed(1)}/${sourceSizeMb} MB, `
+ `${(copiedBytes / 1024 / 1024 / elapsedSeconds).toFixed(1)} MB/s)`,
);
nextProgressPercent = (Math.floor(percent / 10) + 1) * 10;
lastReportedPercent = percent;
});
rd.pipe(wr);
});
@@ -72,13 +72,19 @@ const copyWithProgress = async ({
const copyOnceWithNative = () => new Promise((resolve, reject) => {
const startMs = Date.now();
let settled = false;
let lastReportedPercent = -1;
const progressTimer = setInterval(() => {
if (settled || !fs.existsSync(destination)) return;
const copiedBytes = fs.statSync(destination).size;
const elapsedSeconds = Math.max((Date.now() - startMs) / 1000, 0.1);
const percent = sourceSize === 0
? 99
: Math.min(Math.floor((copiedBytes / sourceSize) * 100), 99);
if (percent <= lastReportedPercent) return;
lastReportedPercent = percent;
report(
Math.floor((copiedBytes / sourceSize) * 100),
`[${label}] Progress: ${Math.min(Math.floor((copiedBytes / sourceSize) * 100), 100)}% `
percent,
`[${label}] Progress: ${percent}% `
+ `(${(copiedBytes / 1024 / 1024).toFixed(1)}/${sourceSizeMb} MB, `
+ `${(copiedBytes / 1024 / 1024 / elapsedSeconds).toFixed(1)} MB/s)`,
);
+2
View File
@@ -227,6 +227,8 @@ const AUDIO_INPUTS = {
ok(copyHelperCode.includes("copyMethod === 'stream'"), 'copy helper supports stream fallback');
ok(copyHelperCode.includes('bufferSizeMb = 16'), 'copy helper defaults stream buffer to 16 MB');
ok(copyHelperCode.includes('128'), 'copy helper caps stream buffer size');
ok(copyHelperCode.includes('Math.min(Math.floor((copiedBytes / sourceSize) * 100), 99)'), 'native progress reserves 100% for completed copy');
ok(copyHelperCode.includes('percent <= lastReportedPercent'), 'copy helper reports each progress percentage once');
// ── Summary ───────────────────────────────────────────────────────────────
console.log(`\n${'='.repeat(55)}`);