# bspatch_sdk **Repository Path**: mousess/bspatch_sdk ## Basic Information - **Project Name**: bspatch_sdk - **Description**: 鸿蒙版基于bsdiff的增量更新 - **Primary Language**: Unknown - **License**: Apache-2.0 - **Default Branch**: main - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2026-03-25 - **Last Updated**: 2026-03-30 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # bspatch_sdk #### 介绍 鸿蒙版基于bsdiff的文件增量更新 bspatch SDK for HarmonyOS/OpenHarmony,用于 .wgt 包的增量合并。 #### 软件架构 软件架构说明 #### 安装教程 `ohpm install @imouse/bspatch_sdk` #### 使用说明 `import { applyPatch } from '@imouse/bspatch_sdk';` 3.1 调用合并(推荐使用 TaskPool 避免阻塞 UI) import { taskpool } from '@kit.ArkTS'; import { common } from '@kit.AbilityKit'; import { fileIo } from '@kit.CoreFileKit'; import { applyPatch } from '@imouse/bspatch_sdk'; // 定义可并发执行的函数 @Concurrent async function applyPatchTask(oldPath: string, newPath: string, patchPath: string): Promise { return applyPatch(oldPath, newPath, patchPath); } async function doIncrementalUpdate() { // 获取应用沙箱路径 const context = getContext() as common.UIAbilityContext; const filesDir = context.filesDir; const oldWgt = filesDir + '/old.wgt'; const newWgt = filesDir + '/new.wgt'; const patch = filesDir + '/update.patch'; // 检查文件是否存在 try { await fileIo.access(oldWgt); await fileIo.access(patch); } catch { console.error('文件不存在'); return; } const task = new taskpool.Task(applyPatchTask, oldWgt, newWgt, patch); try { const success = await taskpool.execute(task) as boolean; if (success) { console.info('合并成功'); // 可在此安装新包或替换旧包 } else { console.error('合并失败'); } } catch (e) { console.error('任务异常', e); } } 3.2 或者新建PatchTask.ets工具类, import { applyPatch } from '@imouse/bspatch_sdk'; @Concurrent export async function applyPatchTask(oldPath: string, newPath: string, patchPath: string): Promise { return applyPatch(oldPath, newPath, patchPath); } 页面内使用 import { applyPatchTask } from './PatchTask' const task = new taskpool.Task(applyPatchTask, oldWgt, newWgt, patch); try { const success = await taskpool.execute(task) as boolean; if (success) { console.info('合并成功'); // 可在此安装新包或替换旧包 } else { console.error('合并失败'); } } catch (e) { console.error('任务异常', e); }