From 386fc7d4c764912447906324b77d83223052ac9e Mon Sep 17 00:00:00 2001 From: ben Date: Sat, 10 Aug 2002 00:43:04 +0000 Subject: Fixed bad high bit permissions mode in cmodule.c, and assorted changes to make --windows-mode work. git-svn-id: http://svn.savannah.nongnu.org/svn/rdiff-backup/trunk@180 2b77aa54-bcbc-44c9-a7ec-4f6cf2b41109 --- rdiff-backup/src/librsync.py | 39 ++++++++++++++++++++++++++++++++++++++- 1 file changed, 38 insertions(+), 1 deletion(-) (limited to 'rdiff-backup/src/librsync.py') diff --git a/rdiff-backup/src/librsync.py b/rdiff-backup/src/librsync.py index 8535532..207d6a9 100644 --- a/rdiff-backup/src/librsync.py +++ b/rdiff-backup/src/librsync.py @@ -110,7 +110,6 @@ class SigFile(LikeFile): try: self.maker = _librsync.new_sigmaker() except _librsync.librsyncError, e: raise librsyncError(str(e)) - class DeltaFile(LikeFile): """File-like object which incrementally generates a librsync delta""" def __init__(self, signature, new_file): @@ -147,3 +146,41 @@ class PatchedFile(LikeFile): try: self.maker = _librsync.new_patchmaker(basis_file) except _librsync.librsyncError, e: raise librsyncError(str(e)) + +class SigGenerator: + """Calculate signature. + + Input and output is same as SigFile, but the interface is like md5 + module, not filelike object + + """ + def __init__(self): + """Return new signature instance""" + try: self.sig_maker = _librsync.new_sigmaker() + except _librsync.librsyncError, e: raise librsyncError(str(e)) + self.gotsig = None + self.buffer = "" + self.sig_string = "" + + def update(self, buf): + """Add buf to data that signature will be calculated over""" + if self.gotsig: + raise librsyncError("SigGenerator already provided signature") + self.buffer += buf + while len(self.buffer) >= blocksize: + if self.process_buffer(): + raise librsyncError("Premature EOF received from sig_maker") + + def process_buffer(self): + """Run self.buffer through sig_maker, add to self.sig_string""" + try: eof, len_buf_read, cycle_out = self.sig_maker.cycle(self.buffer) + except _librsync.librsyncError, e: raise librsyncError(str(e)) + self.buffer = self.buffer[len_buf_read:] + self.sig_string += cycle_out + return eof + + def getsig(self): + """Return signature over given data""" + while not self.process_buffer(): pass # keep running until eof + return self.sig_string + -- cgit v1.2.1