aboutsummaryrefslogtreecommitdiff
path: root/librsync/librsync_callback.go
diff options
context:
space:
mode:
Diffstat (limited to 'librsync/librsync_callback.go')
-rw-r--r--librsync/librsync_callback.go31
1 files changed, 31 insertions, 0 deletions
diff --git a/librsync/librsync_callback.go b/librsync/librsync_callback.go
new file mode 100644
index 0000000..c8b9e4f
--- /dev/null
+++ b/librsync/librsync_callback.go
@@ -0,0 +1,31 @@
+package librsync
+
+/*
+#include <stdio.h>
+#include <librsync.h>
+*/
+import "C"
+
+import (
+ "io"
+ "unsafe"
+)
+
+//export patchCallbackGo
+func patchCallbackGo(_patcher unsafe.Pointer, pos C.rs_long_t, len *C.size_t, _buf *unsafe.Pointer) C.rs_result {
+ patcher := (*Patcher)(_patcher)
+
+ patcher.buf = make([]byte, int(*len))
+ n, err := patcher.basis.ReadAt(patcher.buf, int64(pos))
+ if n < int(*len) {
+ if err != io.EOF {
+ panic(jobInternalPanic{err})
+ } else {
+ return C.RS_INPUT_ENDED
+ }
+ }
+ *len = C.size_t(n)
+ *_buf = unsafe.Pointer(&(patcher.buf[0]))
+
+ return C.RS_DONE
+}