Code to easily develop librsync bindings

This commit is contained in:
Kovid Goyal 2021-10-02 07:22:33 +05:30
parent 0e9be57119
commit f85f39e662
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C
2 changed files with 18 additions and 1 deletions

View File

@ -136,3 +136,20 @@ class PatchFile(StreamingJob):
def __exit__(self, *a: object) -> None:
self.close()
def develop() -> None:
import sys
src = sys.argv[-1]
sig_loader = LoadSignature()
with open(src + '.sig', 'wb') as f:
for chunk in signature_of_file(src):
sig_loader(chunk)
f.write(chunk)
sig_loader()
with open(src + '.delta', 'wb') as f, PatchFile(src, src + '.output') as patcher:
for chunk in delta_for_file(src, sig_loader.signature):
f.write(chunk)
patcher.write(chunk)
if not patcher.finished:
patcher.write(b'')

View File

@ -156,7 +156,7 @@ copy_callback(void *opaque, rs_long_t pos, size_t *len, void **buf) {
if (!mem) { PyErr_Clear(); return RS_MEM_ERROR; }
PyObject *res = PyObject_CallFunction(callback, "OL", mem, p);
Py_DECREF(mem);
if (res == NULL) { PyErr_Clear(); return RS_IO_ERROR; }
if (res == NULL) { PyErr_Print(); return RS_IO_ERROR; }
rs_result r = RS_DONE;
if (PyLong_Check(res)) { *len = PyLong_AsSize_t(res); }
else { r = RS_INTERNAL_ERROR; }