From 579ab8551e5aff374f18b0bd566f80f86464af1c Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Thu, 6 Jul 2023 00:06:26 +0530 Subject: [PATCH] Add some API docs --- tools/rsync/api.go | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/tools/rsync/api.go b/tools/rsync/api.go index 41767c040..1c6db5b53 100644 --- a/tools/rsync/api.go +++ b/tools/rsync/api.go @@ -178,16 +178,20 @@ func write_block_hash(output []byte, bl BlockHash) []byte { return output } -// Create a signature for the data source in src -func (self *Patcher) CreateSignatureIterator(src io.Reader) func([]byte) ([]byte, error) { +// Append the next signature to the provided slice and return the resulting slice. Data is written to the slice iff err == nil. +// When no more signature data is available, err = io.EOF and the unmodified slice is returned. +type SignatureIterator = func([]byte) ([]byte, error) + +// Create a signature for the data source in src. +func (self *Patcher) CreateSignatureIterator(src io.Reader) SignatureIterator { var it func() (BlockHash, error) finished := false return func(output []byte) ([]byte, error) { if finished { - return output, nil + return output, io.EOF } - var b []byte - if it == nil { + if it == nil { // write signature header + var b []byte it = self.rsync.CreateSignatureIterator(src) output, b = ensure_size(output, 12) bin.PutUint32(b, 0)