sisong / HDiffPatch

a C\C++ library and command-line tools for Diff & Patch between binary files or directories(folder); cross-platform; runs fast; create small delta/differential; support large files and limit memory requires when diff & patch.
Other
1.52k stars 280 forks source link

Android 平台下 oldFile 是否能够支持通过 AssetManager 来加载文件,目前看 oldFile 的路径如果是 assets 目录,那么会打开失败 #332

Closed ilinchunjie closed 1 year ago

sisong commented 1 year ago

你可能需要重新包装一下 patch_decompress_with_cachepatch_single_stream (根据你的diff选择)
它们的函数接口需要输入输出数据为流,可以借鉴我对文件访问的包装方式。

推荐做法:
如果你的assets中的old数据没有压缩,那就实现起来很简单,用现有的文件流包装器应该就能支持:获取old数据在apk文件中的起始位置和长度,通过jni函数patch传入 本apk文件、old在apk中位置和长度(后两项为新增参数),在现有代码打开apk流后,添加设置流的偏移位置(hpatch_TFileStreamInput_setOffset)和流大小。 整个过程代码改动很小就能兼容。

如果 assets中的old数据有压缩,那就不能直接使用了,因为hpatch时要求old数据支持随机访问,所以建议将old数据解压另存为文件或者解压在内存中抽象成流来使用(mem_as_hStreamInput)。

ilinchunjie commented 1 year ago

好滴,我尝试一下,感谢回复 @sisong