A native python implementation of the rdiff tool by librsync
Slowing down. Last release over 2 years ago, little activity since. Fine for existing code; think twice for a new project.
pip install rdiffRDIFF
This project is an implementation of the rdiff tool of librsync used for finding the diff of a file on a remote machine. (https://github.com/librsync/librsync/blob/master/doc/rdiff.md).
Note:
This tool isn't concerned with how the signature, and delta files are sent/received over the network. It's only concerned with working with these files and performing the patch.
Usage:
Assume two machines, machine A and machine B, have different versions of the same file.
Machine A wants to synchronise its file with the file present on machine B.
The following example shows the usage of rdiff on Machine A
import rdiff
# create an instance of the checksum class
checksum = rdiff.signature.Checksum()
# Create an instance of the signature class, passing in the checksum object
# Optionally a blocksize can be specified, defaults to 1024 bytes
signature = rdiff.signature.Signature(checksum=checksum)
# create the signature file
# basisFilePath -> Path to the file for which signature must be generated
# sigFilePath -> Where to store the signature file
signature.createSignature(basisFilePath="path_to_file", sigFilePath="path_to_signature_file")
# This machine sends over the signature file to the remote machine
# The remote machine responds back with a delta file
# rdiff isn't concerned with how this communication over the network takes place
patcher = rdiff.patch.Patch()
# Perform a patch operation
# How the delta file is obtained from the remote machine is not a concern of rdiff
# deltaFilePath -> Path to the delta file obtained from the remote machine
# basisFilePath -> Path to the file which is to be updated
# outFilePath -> Path to store the updated file
# Note: The original file isn't modified, instead a new file is created.
patcher.patchFile(
deltaFilePath="path_to_delta_file", basisFilePath="path_to_file", outFilePath="path_to_updated_file"
)
The following shows the usage of rdiff on machine B
import rdiff
# create an instance of the checksum class
checksum = rdiff.signature.Checksum()
# create an instance of the delta class
delta = rdiff.delta.Delta()
# The createDelatFile method is used to create a delta file, for a given file
# against a signature file obtained from a remote machine.
# inFilePath -> Path to the updated file, the file which the remote machine wants to synchronise
# deltatFilePath -> Path to store the delta file
# sigFielPath -> Path to the signature file obtained from the remote machine.
# rdiff is not concerned with how this signature file is obtained.
# blocksize -> This should be identical to the blocksize used by the remote machine to generate the
# signature file.
delta.createDeltaFile(
inFilePath="path_to_updated_file", deltaFilePath="path_to_delta_file",
sigFielPath="path_to_sig_file", blockSize=1024, checksum=checksum
)
# This machine now sends the delta file to the remote machine.