Package: bsdiffhs
> :warning: bsdiffhs is a derivative work from bsdiff4:
bsdiffhs is similar to bsdiff4 (https://github.com/ilanschnell/bsdiff4)
but distinct in its approach to use heatshrink compression algorithm instead of gzip2 format.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
athttp://www.daemonology.net/bsdiff.
In addition to the two functions (diff and patch) cx_bsdiff provides, this
package includes:an interface to the BSDIFFHS-formatcommand line interfaces: bsdiffhs and bspatchhstestsThe bsdiffhs package defines the following high level functions:diff(src_bytes, dst_bytes, window_sz2=10, lookahead_sz2=4)-> bytesReturn a BSDIFFHS-format patch (fromsrc_bytestodst_bytes) as
bytes.patch(src_bytes, patch_bytes, window_sz2=10, lookahead_sz2=4)-> bytesApply the BSDIFFHS-formatpatch_bytestosrc_bytesand return
the bytes.file_diff(src_path, dst_path, patch_path, window_sz2=10, lookahead_sz2=4)Write a BSDIFFHS-format patch (from the filesrc_pathto the
filedst_path) to the filepatch_path.file_patch(src_path, dst_path, patch_path, window_sz2=10, lookahead_sz2=4)Apply the BSDIFFHS-format filepatch_pathto the filesrc_pathand write the result to the filedst_path.file_patch_inplace(path, patch_path, window_sz2=10, lookahead_sz2=4)Apply the BSDIFFHS-format filepatch_pathto the filepathin place.Compression configuration:According to official heatshrink documentation: heatshrink has a couple configuration options, which impact its resource
usage and how effectively it can compress data. These are set when
dynamically allocating an encoder or decoder, or inheatshrink_config.hif they are statically allocated.window_sz2, Set the window size to 2^W bytes.The window size determines how far back in the input can be searched for
repeated patterns. Awindow_sz2of 8 will only use 256 bytes (2^8),
while awindow_sz2of 10 will use 1024 bytes (2^10). The latter uses
more memory, but may also compress more effectively by detecting more
repetition.Thewindow_sz2setting currently must be between 4 and 15.lookahead_sz2, Set the lookahead size to 2^L bytes.The lookahead size determines the max length for repeated patterns that
are found. If thelookahead_sz2is 4, a 50-byte run of ‘a’ characters
will be represented as several repeated 16-byte patterns (2^4 is 16),
whereas a largerlookahead_sz2may be able to represent it all at
once. The number of bits used for the lookahead size is fixed, so an
overly large lookahead size can reduce compression by adding unused
size bits to small patterns.Thelookahead_sz2setting currently must be between 3 and thewindow_sz2- 1.Compression recommandation:Still based on official heatshrink documentation :for embedded/low memory contexts, a `window_sz2in the 8 to 10 range is
probably a good default, depending on how tight memory is. Smaller or
larger window sizes may make better trade-offs in specific
circumstances, but should be checked with representative data.Thelookahead_sz2should probably start near thewindow_sz2/2, e.g.
-w 8 -l 4 or -w 10 -l 5. The command-line program can be used to measure
how well test data works with different settings.`Example:>>>importbsdiffhs>>>a=100000*b'a'>>>b=bytearray(a)>>>b[100:106]=b' diff '>>>p=bsdiffhs.diff(a,bytes(b),11,5)>>>len(p)154>>>bsdiffhs.patch(a,p,11,5)==bTrue