No description
  • C 87.9%
  • Shell 11.2%
  • Makefile 0.9%
Find a file
Gergely Gati d08162b4c3
Update README to include bsdiff link
Added a link to the bsdiff patch algorithm in the README.
2025-12-07 19:22:01 -08:00
.gitignore Initial commit 2025-11-29 07:08:36 -08:00
LICENSE Initial commit 2025-11-29 07:08:36 -08:00
Makefile test suite added 2025-11-29 09:05:42 -08:00
README.md Update README to include bsdiff link 2025-12-07 19:22:01 -08:00
sbsdiff.c initial commit 2025-11-29 07:39:42 -08:00
sbsp.c test suite added 2025-11-29 09:05:42 -08:00
sbsp.h refactoring naming 2025-11-29 08:42:06 -08:00
test.sh test suite added 2025-11-29 09:05:42 -08:00
testgen.sh test suite added 2025-11-29 09:05:42 -08:00

sbspatch

A header-only, streaming re-implementation of the bsdiff patch algorithm (bspatch), built for low-memory environments and embedded systems.

Features

  • Streaming API

    • Process arbitrary input buffer sizes.
    • Call sbsp_patch() repeatedly as data arrives.
    • Returns:
      • SBSP_MORE → more bytes needed
      • SBSP_DONE → patching complete
    • No file I/O, no dynamic memory allocations.
  • Uncompressed Patch Format

    • Patch data is stored uncompressed, making it roughly the size of the original or new file.
    • The output is highly compressible. Users are expected to apply their own compression when storing or transferring patches.
  • Custom Magic

    • Uses "BSGG" instead of the original "ENDSLEY/BSDIFF43, allowing safe identification of the modified format.
  • Fixed-size, small-chunk output writes

    • Internal output buffer size can be configurable (default is 4 bytes) (SBSP_WRITE_CHUNK), tunable via compile-time define.
    • Designed for systems that write data in smaller blocks (e.g., flash pages, stream sinks, network packetizers).

Usage

#define SBSP_IMPLEMENTATION
#include "sbsp.h"

struct sbsp bs;

sbsp_init(&bs, oldfile, oldsize, my_write_callback, my_userdata);

while(stream_has_data()) {
  int r = sbsp_patch(&bs, incoming_buffer, incoming_len);
  if(r == SBSP_DONE) break;
  if(r < 0) {
    // handle error
    break;
  }
}

Write Callback

int my_write(void *userdata, int position, uint8_t *data, int len);
  • userdata → user pointer from init
  • position → offset to write to
  • data, len → output bytes and length
  • Return < 0 for failure

License

This code is based on the principles of bsdiff/bspatch by Colin Percival and modified by Matthew Endsley, rewritten for streaming and embedded use cases. This implementation is not binary compatible with the original format due to header and compression changes.