Development Status
- 5 - Production/Stable
Intended Audience
- Developers
Operating System
- OS Independent
Programming Language
- C
- Python :: 3
- Python :: 3.7
- Python :: 3.8
- Python :: 3.9
- Python :: 3.10
- Python :: 3.11
- Python :: 3.12
- Python :: 3.13
- Python :: 3.14
- Python :: 3.15
- Python :: Free Threading :: 3 - Stable
Topic
- Utilities
The code is mostly derived from cx_bsdiff (written by Anthony Tuininga, http://cx-bsdiff.sourceforge.net/). The cx_bsdiff code in turn was derived from bsdiff, the standalone utility produced for BSD which can be found at http://www.daemonology.net/bsdiff.
Key features of this package include:
produces and applies patches compatible with the standard bsdiff and bspatch tools
high-level diff and patch functions
an interface to the BSDIFF4 format
stricter validation and improved error handling of malformed patches than the standard bspatch tool; in particular overlong blocks are rejected
functions for creating patches from files and applying them to files
command-line interfaces: bsdiff4 and bspatch4 (the latter can also inspect patches using bspatch4 PATCH)
support for free-threaded Python
type hints
extensive tests
The bsdiff4 package defines the following high level functions:
- diff(src_bytes, dst_bytes) -> bytes
Return a BSDIFF4-format patch (from src_bytes to dst_bytes) as bytes.
- patch(src_bytes, patch_bytes) -> bytes
Apply the BSDIFF4-format patch_bytes to src_bytes and return the bytes.
- file_diff(src_path, dst_path, patch_path) -> None
Write a BSDIFF4-format patch (from the file src_path to the file dst_path) to the file patch_path.
- file_patch(src_path, dst_path, patch_path) -> None
Apply the BSDIFF4-format file patch_path to the file src_path and write the result to the file dst_path.
- file_patch_inplace(path, patch_path) -> None
Apply the BSDIFF4-format file patch_path to the file path in place.
Example:
>>> import bsdiff4
>>> a = 100_000 * b'a'
>>> b = bytearray(a)
>>> b[100:106] = b' diff '
>>> p = bsdiff4.diff(a, bytes(b))
>>> len(p)
153
>>> bsdiff4.patch(a, p) == b
True