概述追加与区间覆盖可提高更新效率。本文提供最小用法。追加与覆盖async function appendText() {
const handle = await window.showSaveFilePicker({ suggestedName: 'log.txt' });
const ws = await handle.createWritable({ keepExistingData: true });
const file = await handle.getFile();
await ws.seek(file.size);
await ws.write(new Blob(['\nappend line'], { type: 'text/plain' }));
await ws.close();
}
async function coverRange(pos, bytes) {
const handle = await window.showSaveFilePicker({ suggestedName: 'data.bin' });
const ws = await handle.createWritable({ keepExistingData: true });
await ws.write({ type: 'write', position: pos, data: bytes });
await ws.close();
}

发表评论 取消回复