Example #1
0
 def _findmatch(self):
     "return a match tuple, or raise KeyError if there isn't one"
     # get the adler32 digest, and calculate sig if needed
     try:
         sig=self.sig.digest()
     except AttributeError:
         sig=self.sig=adler32.new(buffer(self.data,self.pos,self.blocksize))
         sig=self.sig.digest()
     # get the matching offset, if it exists, otherwise raise KeyError
     offset,length=self.sigtable[sig],0
     # extend the match forwards
     while (self.pos+length<len(self.data) and
            self._read(offset+length)==self.data[self.pos+length]):
         length=length+1
     # if the match was too short, there was no match
     if length<=8:
         raise KeyError
     # extend the match backwards
     while (self.pos and offset and
            self._read(offset-1)==self.data[self.pos-1]):
         self.pos,offset,length=self.pos-1,offset-1,length+1
     # reset last miss if extending backwards removes it
     if self.pos==0 and self.last=="":
         self.last=None
     return offset,length
Example #2
0
 def __init__(self,oldfile,blocksize=512):
     self.oldfile=oldfile
     sigtable={}
     offset,data=0,oldfile.read(blocksize)
     while data:
         sig=adler32.new(data).digest()
         if not sigtable.has_key(sig):
             sigtable[sig]=offset
         offset,data=offset+len(data),oldfile.read(blocksize)
     rdeltaobj.__init__(self,(offset,blocksize,sigtable))
Example #3
0
 def _findmatch(self):
     "return a match tuple, or raise KeyError if there isn't one"
     # get the adler32 digest, calculating sig if needed
     try:
         sig=self.sig.digest()
     except AttributeError:
         self.sig=adler32.new(buffer(self.data,self.pos,self.blocksize))
         sig=self.sig.digest()
     # get the matching offset, if it exists, otherwise raise KeyError
     sumtable=self.sigtable[sig]
     sum=md4.new(buffer(self.data,self.pos,self.blocksize))
     return sumtable[sum.digest()],self.sig.count
Example #4
0
def calcsig(oldfile,blocksize=BLOCK_SIZE):
    "Calculates and returns a signature"
    offset=0
    sigtable={}
    data=oldfile.read(blocksize)
    while data:
        sum=md4.new(data).digest()
        sig=adler32.new(data).digest()
        try:
            sigtable[sig][sum]=offset
        except KeyError:
            sigtable[sig]={}
            sigtable[sig][sum]=offset
        offset=offset+len(data)
        data=oldfile.read(blocksize)
    return (offset,blocksize,sigtable)