Esempio n. 1
0
    def get_delta(self, old_buf, new_buf):
        u"""Return delta buffer from old to new"""
        sigfile = librsync.SigFile(io.BytesIO(old_buf))
        sig = sigfile.read()
        assert not sigfile.close()

        deltafile = librsync.DeltaFile(sig, io.BytesIO(new_buf))
        deltabuf = deltafile.read()
        assert not deltafile.close()
        return deltabuf
Esempio n. 2
0
def librsyncDeltaFile(filename, signature, deltafile):
    bufsize = 1024 * 1024
    filename = forceFilename(filename)
    deltafile = forceFilename(deltafile)
    logger.debug("Creating deltafile {!r} on base of {!r}", deltafile,
                 filename)
    try:
        with open(filename, "rb") as f:
            with open(deltafile, "wb") as df:
                with closing(librsync.DeltaFile(signature, f)) as ldf:
                    data = True
                    while data:
                        data = ldf.read(bufsize)
                        df.write(data)
    except Exception as e:
        raise RuntimeError(u"Failed to write delta file %s: %s" %
                           (deltafile, forceUnicode(e)))