`title: OPFS 导出到用户目录:File System Access 目录桥接``categories: Web 开发/前端/数据管理``keywords: OPFS,File System Access,showDirectoryPicker,导出,备份``description: 使用 File System Access 的目录选择将 OPFS 文件导出到用户目录,实现备份与跨设备迁移的友好体验。`导出示例async function exportOPFS() { const root = await navigator.storage.getDirectory(); const dest = await window.showDirectoryPicker(); for await (const [name, handle] of root.entries()) { if (handle.kind === 'file') { const file = await handle.getFile(); const out = await dest.getFileHandle(name, { create: true }); const w = await out.createWritable(); await w.write(await file.arrayBuffer()); await w.close(); } } }

发表评论 取消回复