feat: 集成漫画源并支持在线阅读

This commit is contained in:
lofyer
2026-08-08 19:32:47 +08:00
parent c2292da442
commit 87dcc307e6
30 changed files with 3681 additions and 58 deletions
+33
View File
@@ -89,3 +89,36 @@ test('目录 fsync 失败不影响写入结果', () => {
}
assert.deepStrictEqual(JSON.parse(fs.readFileSync(dest, 'utf8')), { ok: true });
});
test('writeBytes 原子覆盖二进制文件且不残留临时文件', () => {
const dir = fresh('bytes');
const dest = path.join(dir, 'book.epub');
fs.writeFileSync(dest, Buffer.from([1, 2, 3]));
atomic.writeBytes(dest, Buffer.from([4, 5, 0, 255]));
assert.deepStrictEqual([...fs.readFileSync(dest)], [4, 5, 0, 255]);
assert.strictEqual(fs.existsSync(`${dest}.tmp`), false);
assert.strictEqual(fs.existsSync(`${dest}.bak`), false);
});
test('writeBytes 替换失败时恢复旧二进制内容', () => {
const dir = fresh('bytes-rollback');
const dest = path.join(dir, 'book.epub');
fs.writeFileSync(dest, Buffer.from([1, 2, 3]));
const realRename = fs.renameSync;
let failed = false;
fs.renameSync = function failing(from, to) {
if (!failed && String(from) === `${dest}.tmp` && String(to) === dest) {
failed = true;
throw new Error('模拟二进制替换失败');
}
return realRename.apply(this, arguments);
};
try {
assert.throws(() => atomic.writeBytes(dest, Buffer.from([9, 9])), /模拟二进制替换失败/);
} finally {
fs.renameSync = realRename;
}
assert.deepStrictEqual([...fs.readFileSync(dest)], [1, 2, 3]);
assert.strictEqual(fs.existsSync(`${dest}.tmp`), false);
assert.strictEqual(fs.existsSync(`${dest}.bak`), false);
});