`title: OPFS 归档压缩与解压协作实践``categories: Web 开发/前端/数据管理``keywords: OPFS,归档,压缩,解压,Compression Streams``description: 在 OPFS 中管理归档文件,结合 Compression Streams 进行压缩与解压,配合索引与清理策略提升可控性。`压缩写入async function gzipToOPFS(name, stream) { const root = await navigator.storage.getDirectory(); const h = await root.getFileHandle(name, { create: true }); const w = await h.createWritable(); await stream.pipeThrough(new CompressionStream('gzip')).pipeTo(w); } 解压读取async function gunzipFromOPFS(h) { const file = await h.getFile(); return file.stream().pipeThrough(new DecompressionStream('gzip')); }

发表评论 取消回复