Fuck Bun for write file in stream

This commit is contained in:
SukkaW 2024-04-04 00:35:51 +08:00
parent b48bdb104b
commit 8a1aa15ea0

View File

@ -18,6 +18,9 @@ export async function compareAndWriteFile(span: Span, linesA: string[], filePath
console.log(`Nothing to write to ${filePath}...`);
isEqual = false;
} else {
/* The `isEqual` variable is used to determine whether the content of a file is equal to the
provided lines or not. It is initially set to `true`, and then it is updated based on different
conditions: */
isEqual = await span.traceChildAsync(`comparing ${filePath}`, async () => {
let index = 0;
@ -64,18 +67,17 @@ export async function compareAndWriteFile(span: Span, linesA: string[], filePath
}
await span.traceChildAsync(`writing ${filePath}`, async () => {
if (linesALen < 10000) {
return Bun.write(file, `${linesA.join('\n')}\n`);
}
// if (linesALen < 10000) {
return Bun.write(file, `${linesA.join('\n')}\n`);
// }
// const writer = file.writer();
const writer = file.writer();
// for (let i = 0; i < linesALen; i++) {
// writer.write(linesA[i]);
// writer.write('\n');
// }
for (let i = 0; i < linesALen; i++) {
writer.write(linesA[i]);
writer.write('\n');
}
return writer.end();
// return writer.end();
});
}