mirror of
https://github.com/ollama/ollama.git
synced 2026-04-24 01:35:49 +02:00
Add 'x/' from commit 'a10a11b9d371f36b7c3510da32a1d70b74e27bd1'
git-subtree-dir: x git-subtree-mainline:7d05a6ee8fgit-subtree-split:a10a11b9d3
This commit is contained in:
27
x/utils/upload/upload.go
Normal file
27
x/utils/upload/upload.go
Normal file
@@ -0,0 +1,27 @@
|
||||
package upload
|
||||
|
||||
import (
|
||||
"iter"
|
||||
|
||||
"golang.org/x/exp/constraints"
|
||||
)
|
||||
|
||||
type Chunk[I constraints.Integer] struct {
|
||||
Offset I
|
||||
Size I
|
||||
}
|
||||
|
||||
// Chunks yields a sequence of a part number and a Chunk. The Chunk is the offset
|
||||
// and size of the chunk. The last chunk may be smaller than chunkSize if size is
|
||||
// not a multiple of chunkSize.
|
||||
//
|
||||
// The first part number is 1 and increases monotonically.
|
||||
func Chunks[I constraints.Integer](size, chunkSize I) iter.Seq2[int, Chunk[I]] {
|
||||
return func(yield func(int, Chunk[I]) bool) {
|
||||
var n int
|
||||
for off := I(0); off < size; off += chunkSize {
|
||||
n++
|
||||
yield(n, Chunk[I]{off, min(chunkSize, size-off)})
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user