Fix: compare and write file with empty line

This commit is contained in:
SukkaW 2025-04-21 21:09:55 +08:00
parent 028d50d928
commit 1321f6d9db
2 changed files with 17 additions and 1 deletions

View File

@ -86,4 +86,10 @@ describe('fileEqual', () => {
['A', 'B', ''], ['A', 'B', ''],
false false
)); ));
it('sgmodule', () => test(
['#!name=[Sukka] URL Redirect', '#!desc=Last Updated: 2025-04-21T13:01:42.570Z Size: 127', '', 'always-real-ip'],
['#!name=[Sukka] URL Redirect', '#!desc=Last Updated: 2025-04-20T13:01:42.570Z Size: 130', '', 'always-real-ip'],
true
));
}); });

View File

@ -40,6 +40,16 @@ export async function fileEqual(linesA: string[], source: AsyncIterable<string>
const lineA = linesA[index]; const lineA = linesA[index];
if (lineA.length === 0) {
if (lineB.length === 0) {
// eslint-disable-next-line no-await-in-loop -- sequential
result = await iterator.next();
lineB = result.value;
continue;
}
return false;
}
const aFirstChar = lineA.charCodeAt(0); const aFirstChar = lineA.charCodeAt(0);
if (aFirstChar !== lineB.charCodeAt(0)) { if (aFirstChar !== lineB.charCodeAt(0)) {
return false; return false;
@ -85,7 +95,7 @@ export async function compareAndWriteFile(span: Span, linesA: string[], filePath
return; return;
} }
await span.traceChildAsync(`writing ${filePath}`, async () => { return span.traceChildAsync(`writing ${filePath}`, async () => {
const linesALen = linesA.length; const linesALen = linesA.length;
// The default highwater mark is normally 16384, // The default highwater mark is normally 16384,