MCPcopy Create free account
hub / github.com/cph6/zsync / SubmitTargetData

Method SubmitTargetData

syncer.go:181–223  ·  view source on GitHub ↗

SubmitTargetData takes received blocks of target data and uses them to fill in missing chunks of the target file. Public for advanced use only: most callers should use FetchRemainingBlocks instead and let the Syncer fetch and submit the blocks. This is provided for callers that want to handle data d

(offset int64, in io.Reader)

Source from the content-addressed store, hash-verified

179// callers that want to handle data downloading via another protocol or
180// approach feed the syncer themselves.
181func (zs *Syncer) SubmitTargetData(offset int64, in io.Reader) (int64, error) {
182 bytesReceived := int64(0)
183
184 if offset%zs.blocksize != 0 {
185 panic(fmt.Sprintf("misaligned data block passed as target data (%d, blocksize %d)", offset, zs.blocksize))
186 }
187 id := rcksum.BlockID(offset / zs.blocksize)
188
189 buf := make([]byte, zs.blocksize)
190 var n int
191 var err error
192 for {
193 n, err = io.ReadFull(in, buf)
194 if err != nil {
195 break
196 }
197 bytesReceived += int64(n)
198 // err == nil implies a full buffer.
199 err = zs.rs.SubmitBlocks(buf, id, id)
200 if err != nil {
201 return bytesReceived, err
202 }
203 id++
204 }
205 switch err {
206 case io.EOF:
207 return bytesReceived, nil
208 case io.ErrUnexpectedEOF:
209 if id == rcksum.BlockID(zs.blocks-1) {
210 // Short last block. rcksum expects a full block, padded with 0s, so pad and submit.
211 for i := range buf {
212 if i >= n {
213 buf[i] = 0
214 }
215 }
216 err = zs.rs.SubmitBlocks(buf, id, id)
217 return bytesReceived, err
218 } // else fall through; any other incomplete block is an error.
219 default:
220 // Any other error is returned as-is
221 }
222 return bytesReceived, err
223}
224
225// NewSeedSink returns a io.ReaderFrom that can be used to stream local seed
226// local seed data to the Syncer. progressCallback, if provided, will be

Callers 1

fetchRangeMethod · 0.95

Calls 2

BlockIDTypeAlias · 0.92
SubmitBlocksMethod · 0.80

Tested by

no test coverage detected