用sha256散列实现rsync的python模块。
pyrsync的Python项目详细描述
pyrsync是一个python模块,它实现了[rsync算法][1], 用纯python编写。它不是rsync的包装器,而是一组 通过python应用完整rsync功能的函数。
原始rsync规范要求使用md5散列,其中 这个模块的开发人员认为已经过时了,因此 MD5的出现已替换为SHA256。就我个人而言 选择使用sha512,但这将使散列的存储大小增加一倍 表数据库。SHA256足以满足标准安全性要求 但是,对于本版本中的验证过程的要求, 最终,用户/开发人员可以在 在进一步的发布中,应该考虑使用各种散列。
这个模块的大部分代码来自 在activestate[1]发布。它最初是根据[麻省理工学院许可证]授权的 [2],本许可证未作任何修改。
##安装
如果安装了[setuptools][3],只需执行以下操作:
$ sudo python setup.py install
如果没有setuptools,setup.py脚本将检测到 默认使用python内置distutils。要使用distutils安装, 安装过程与上面记录的setuptools相同。
##使用
此模块的示例用例:
# On the system containing the file that needs to be patched >>> import pyrsync >>> unpatched = open(“unpatched.file”, “rb”) >>> hashes = pyrsync.blockchecksums(unpatched)
# On the remote system after having received hashes >>> import pyrsync >>> patchedfile = open(“patched.file”, “rb”) >>> delta = pyrsync.rsyncdelta(patchedfile, hashes)
# System with the unpatched file after receiving delta >>> unpatched.seek(0) >>> save_to = open(“locally-patched.file”, “wb”) >>> pyrsync.patchstream(unpatched, save_to, delta)
[1]:http://samba.anu.edu.au/rsync/“安德鲁·特里吉尔和保罗·麦凯拉斯。rsync算法。技术报告TR-CS-96-05,堪培拉0200法案,澳大利亚,1996年。” [2]:https://code.activestate.com/recipes/577518-rsync-algorithm/“rsync算法(python配方)” [3]:http://www.opensource.org/licenses/mit-license.php“OSI MIT许可证”