package downloaderimport ()// Verify checks local file data (e.g. a partially downloaded .part file)// against file hashes from the server (upload.getFileHashes) and returns the// length of the longest verified prefix.//// The r must contain the first size bytes of the file. A trailing part// shorter than a hash window can be verified only if it is the end of the// file, otherwise it is not counted.//// If the result equals the file size (e.g. Document.Size), the local file is// complete: do not resume. Otherwise the result ends at a hash window border,// which is 4KB-aligned, and can be passed to WithOffset to resume a download// safely together with WithVerify(true). Without verification, WithOffset// requires the offset to be divisible by the part size, so round the result// down to it://// off -= off % partSizefunc ( *Builder) ( context.Context, io.ReaderAt, int64) ( int64, error) {if <= 0 {return0, nil }if := .downloader.obs; != nil { = .with()deferfunc() { .verified(, , , ) }() } := newVerifier(.schema, .hashes...)var []bytefor { , , := .next()if != nil {return , errors.Wrap(, "get hashes") }if ! || .Offset != || .Offset >= {// No more hashes, unexpected gap, or end of local data.return , nil } := int64(.Limit)if .Offset+ > { = - .Offset }ifint64(cap()) < { = make([]byte, ) } := [:]if , := .ReadAt(, .Offset); != nil && !errors.Is(, io.EOF) {return , errors.Wrap(, "read") }if !.verify(, ) {// Mismatch, or partial window that is not the end of the file.return , nil } = .Offset + if < int64(.Limit) || >= {// Last (short) window of the file, or all local data is // verified: do not ask for hashes past it, Telegram answers // VOLUME_LOC_NOT_FOUND at the end of the file.return , nil } }}
The pages are generated with Goldsv0.8.7. (GOOS=linux GOARCH=amd64)
Golds is a Go 101 project developed by Tapir Liu.
PR and bug reports are welcome and can be submitted to the issue list.
Please follow @zigo_101 (reachable from the left QR code) to get the latest news of Golds.