{"id":19747421,"url":"https://github.com/sisong/hpatchlite","last_synced_at":"2025-10-09T11:13:21.227Z","repository":{"id":39923569,"uuid":"481810788","full_name":"sisong/HPatchLite","owner":"sisong","description":"Lite version of HDiffPatch, tiny code \u0026 ram requires when patch on embedded systems,MCU,NB-IoT,...","archived":false,"fork":false,"pushed_at":"2025-10-02T14:15:33.000Z","size":103,"stargazers_count":119,"open_issues_count":0,"forks_count":37,"subscribers_count":9,"default_branch":"main","last_synced_at":"2025-10-02T16:15:18.661Z","etag":null,"topics":["delta","diff","embedded","hdiffpatch","iot","lite","mcu","nb-iot","patch","tiny"],"latest_commit_sha":null,"homepage":"","language":"C","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/sisong.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2022-04-15T02:22:58.000Z","updated_at":"2025-10-02T14:13:40.000Z","dependencies_parsed_at":"2025-06-19T06:28:00.477Z","dependency_job_id":"ce07555e-8cfe-4b10-b57c-0698792a9923","html_url":"https://github.com/sisong/HPatchLite","commit_stats":null,"previous_names":[],"tags_count":4,"template":false,"template_full_name":null,"purl":"pkg:github/sisong/HPatchLite","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sisong%2FHPatchLite","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sisong%2FHPatchLite/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sisong%2FHPatchLite/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sisong%2FHPatchLite/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/sisong","download_url":"https://codeload.github.com/sisong/HPatchLite/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sisong%2FHPatchLite/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":279001288,"owners_count":26083058,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-10-09T02:00:07.460Z","response_time":59,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["delta","diff","embedded","hdiffpatch","iot","lite","mcu","nb-iot","patch","tiny"],"created_at":"2024-11-12T02:17:47.444Z","updated_at":"2025-10-09T11:13:21.219Z","avatar_url":"https://github.com/sisong.png","language":"C","readme":"# [HPatchLite](https://github.com/sisong/HPatchLite)\n[![release](https://img.shields.io/badge/release-v1.0.1-blue.svg)](https://github.com/sisong/HPatchLite/releases) \n[![license](https://img.shields.io/badge/license-MIT-blue.svg)](https://github.com/sisong/HPatchLite/blob/main/LICENSE) \n[![PRs Welcome](https://img.shields.io/badge/PRs-welcome-blue.svg)](https://github.com/sisong/HPatchLite/pulls)\n[![+issue Welcome](https://img.shields.io/github/issues-raw/sisong/HPatchLite?color=green\u0026label=%2Bissue%20welcome)](https://github.com/sisong/HPatchLite/issues)   \n[![Build Status](https://github.com/sisong/HPatchLite/actions/workflows/ci.yml/badge.svg?branch=main)](https://github.com/sisong/HPatchLite/actions?query=branch%3Amain)   \n english | [中文版](README_cn.md)   \n\nHPatchLite is a lite version of [HDiffPatch](https://github.com/sisong/HDiffPatch), tiny code \u0026 ram requirements when patch on embedded systems,MCU,NB-IoT,...   \nHPatchLite also supports a simple inplace-patch implementation to support storage-constrained devices.   \n\nThe patch code(ROM or flash occupancy) very small, compiled by Mbed Studio is 662 bytes.    \nTip: *if define _IS_RUN_MEM_SAFE_CHECK=0, unsafe mode can reduce 48 bytes; \nif used [tinyuz](https://github.com/sisong/tinyuz) \u0026 define _IS_USED_SHARE_hpatch_lite_types=1, can reduce 52 bytes.*   \n   \nAt the same time, the patch memory(RAM occupancy) can also be very small, \nRAM size = one decompress memory size + input cache size(\u003e=3Byte) when patch.    \nTip: *The smaller input cache only affects the patch speed.*   \n\n---\n## Releases/Binaries\n[Download from latest release](https://github.com/sisong/HPatchLite/releases) : Command line app for Windows, Linux, MacOS.     \n\n## Build it yourself\n### Linux or MacOS X ###\n```\n$ cd \u003cdir\u003e\n$ git clone --recursive https://github.com/sisong/HPatchLite.git\n$ cd HPatchLite\n$ make\n```\n\n### Windows ###\n```\n$ cd \u003cdir\u003e\n$ git clone --recursive https://github.com/sisong/HPatchLite.git\n```\nbuild `HPatchLite/builds/vc/HPatchLite.sln` with [`Visual Studio`](https://visualstudio.microsoft.com)   \n\n---\n## **diff** command line usage:  \n```\ndiff    usage: hdiffi [options] oldFile newFile outDiffFile\ntest    usage: hdiffi    -t     oldFile newFile testDiffFile\n  oldFile can empty, and input parameter \"\"\noptions:\n  -m[-matchScore]\n      requires (newFileSize+ oldFileSize*5(or *9 when oldFileSize\u003e=2GB))+O(1)\n        bytes of memory;\n      matchScore\u003e=0, DEFAULT -m-6\n  -inplace[-extraSafeSize]\n      open create inplace-patch mode, DEFAULT closed;\n      extraSafeSize: extra safe access distances for inplace-patch;\n      extraSafeSize\u003e=0, DEFAULT 0;\n      if extraSafeSize\u003e0, need use extra space to cache new data when patch,\n        thus increasing the chance of matchmaking when diff, also increases\n        the memory usage by the same amount when patch and increases the\n        complexity of patch code.\n  -cache\n      set is use a big cache for slow match, DEFAULT false;\n      if newData not similar to oldData then diff speed++,\n      big cache max used O(oldFileSize) memory, and build slow(diff speed--)\n  -p-parallelThreadNumber\n      if parallelThreadNumber\u003e1 then open multi-thread Parallel mode;\n      DEFAULT -p-4; requires more memory!\n  -c-compressType[-compressLevel]\n      set outDiffFile Compress type, DEFAULT uncompress;\n      support compress type \u0026 level \u0026 dict:\n        -c-tuz[-dictSize]               (or -c-tinyuz)\n        -c-tuzi[-dictSize]              (or -c-tinyuzi)\n            1\u003c=dictSize\u003c=1g, can like 250,511,1k,4k,64k,1m,64m..., DEFAULT 32k\n            Note: -c-tuz is default compressor;\n            But if your compile tinyuz deccompressor source code by yourself,\n             \u0026 set tuz_isNeedLiteralLine=0, then must used -c-tuzi compressor.\n        -c-zlib[-{1..9}[-dictBits]]     DEFAULT level 9\n            dictBits can 9--15, DEFAULT 15.\n        -c-pzlib[-{1..9}[-dictBits]]    DEFAULT level 6\n            dictBits can 9--15, DEFAULT 15.\n            support run by multi-thread parallel, fast!\n        -c-lzma[-{0..9}[-dictSize]]     DEFAULT level 7\n            dictSize can like 4096 or 4k or 4m or 128m etc..., DEFAULT 32k\n            support run by 2-thread parallel.\n        -c-lzma2[-{0..9}[-dictSize]]    DEFAULT level 7\n            dictSize can like 4096 or 4k or 4m or 128m etc..., DEFAULT 32k\n            support run by multi-thread parallel, fast!\n            WARNING: code not compatible with it compressed by -c-lzma!\n  -d  Diff only, do't run patch check, DEFAULT run patch check.\n  -t  Test only, run patch check, patch(oldFile,testDiffFile)==newFile ?\n  -f  Force overwrite, ignore write path already exists;\n      DEFAULT (no -f) not overwrite and then return error;\n      if used -f and write path is exist directory, will always return error.\n  --patch\n      swap to hpatchi mode.\n  -v  output Version info.\n  -h (or -?)\n      output usage info.\n```\n\n## **patch** command line usage:  \n```\npatch   usage: hpatchi [options] oldFile diffFile outNewFile\ninplace-patch: hpatchi [options] oldFile diffFile -INPLACE\n  if oldFile is empty input parameter \"\"\noptions:\n  -s[-cacheSize]\n      DEFAULT -s-32k; cacheSize\u003e=3, can like 256,1k, 60k or 1m etc....\n      requires (cacheSize + 1*decompress buffer size [+ extraSafeSize for inplace-patch])+O(1) bytes of memory.\n  -INPLACE\n      open inplace-patch mode, DEFAULT closed;\n      WANING: oldFile will be modified to newFile when inplace-patch successful,\n           and it will be damaged \u0026 cannot be recovered when inplace-patch fail.\n  -f  Force overwrite, ignore write path already exists;\n      DEFAULT (no -f) not overwrite and then return error;\n      if used -f and write path is exist directory, will always return error.\n  -v  output Version info.\n  -h  (or -?)\n      output usage info.\n```\n\n---\n## library API usage:\ncreate hpatch_lite diff:\n```\ncreate_lite_diff(newData,OldData,out_lite_diff,compressPlugin,...);\n```\napply patch:\n```\nhpi_BOOL hpatch_lite_open(hpi_TInputStreamHandle diff_data,hpi_TInputStream_read read_diff,\n                          hpi_compressType* out_compress_type,hpi_pos_t* out_newSize,hpi_pos_t* out_uncompressSize);\nhpi_BOOL hpatch_lite_patch(hpatchi_listener_t* listener,hpi_pos_t newSize,\n                           hpi_byte* temp_cache,hpi_size_t temp_cache_size);\n```\ncreate inplaceB diff:\n```\ncreate_inplaceB_lite_diff(newData,OldData,out_lite_diff,extraSafeSize,compressPlugin,...);\n```\napply inplaceB patch:\n```\nhpi_BOOL hpatchi_inplace_open(hpi_TInputStreamHandle diff_data,hpi_TInputStream_read read_diff,\n                              hpi_compressType* out_compress_type,hpi_pos_t* out_newSize,\n                              hpi_pos_t* out_uncompressSize,hpi_size_t* out_extraSafeSize);\nhpi_BOOL hpatchi_inplaceB(hpatchi_listener_t* listener,hpi_pos_t newSize,\n                          hpi_byte* temp_cache,hpi_size_t extraSafeSize_in_temp_cache,hpi_size_t temp_cache_size);\n```\n\n---\n## Porting patch algorithm to embedded devices:\n* Add or copy the entire directory `HDiffPatch/libHDiffPatch/HPatchLite/` to your project;\n* Add a reference to the `hpatch_lite.h` header file where the patch algorithm is needed, and call the patch functions declared in this file.\n* Key points of the code: \n  1. Use the `hpatch_lite_open` function to open the patch data, diff_data is the handle pointing to the patch data, and read_diff is the function that reads the patch data sequentially through the handle.\n  1. After opening the patch, you can get the compression algorithm type compress_type used by the patch and the amount of data that can be decompressed uncompressSize; if there is compression, then use the corresponding decompression algorithm to wrap diff_data and read_diff to get new diff_data and read_diff that can read uncompressed data;\n  1. Fill an hpatchi_listener_t structure to call `hpatch_lite_patch`; read_old is used to randomly read the old version of the data, and write_new is used to sequentially write the new version of the newSize size of data.\n  1. If inplace-patch are used, replace `hpatch_lite_open` with `hpatchi_inplace_open` and `hpatch_lite_patch` with `hpatchi_inplaceB`. When alloc memory for temp_cache, memory size need to add **extraSafeSize**. \n  (best practices: If you need to write aligned full-page data each time, you can set _IS_WTITE_NEW_BY_PAGE=1 at compile time so that you can call `hpatchi_inplaceB_by_page`.)\n\n---\n## Contact\nhousisong@hotmail.com  ","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsisong%2Fhpatchlite","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsisong%2Fhpatchlite","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsisong%2Fhpatchlite/lists"}