mirror of
https://gitea.com/Lydanne/buildx.git
synced 2025-07-17 00:47:10 +08:00
vendor: github.com/moby/buildkit v0.21.0-rc2
Signed-off-by: CrazyMax <1951866+crazy-max@users.noreply.github.com>
This commit is contained in:
44
vendor/github.com/tonistiigi/fsutil/buffer.go
generated
vendored
Normal file
44
vendor/github.com/tonistiigi/fsutil/buffer.go
generated
vendored
Normal file
@ -0,0 +1,44 @@
|
||||
package fsutil
|
||||
|
||||
import (
|
||||
"io"
|
||||
)
|
||||
|
||||
const chunkSize = 32 * 1024
|
||||
|
||||
type buffer struct {
|
||||
chunks [][]byte
|
||||
}
|
||||
|
||||
func (b *buffer) alloc(n int) []byte {
|
||||
if n > chunkSize {
|
||||
buf := make([]byte, n)
|
||||
b.chunks = append(b.chunks, buf)
|
||||
return buf
|
||||
}
|
||||
|
||||
if len(b.chunks) != 0 {
|
||||
lastChunk := b.chunks[len(b.chunks)-1]
|
||||
l := len(lastChunk)
|
||||
if l+n <= cap(lastChunk) {
|
||||
lastChunk = lastChunk[:l+n]
|
||||
b.chunks[len(b.chunks)-1] = lastChunk
|
||||
return lastChunk[l : l+n]
|
||||
}
|
||||
}
|
||||
|
||||
buf := make([]byte, n, chunkSize)
|
||||
b.chunks = append(b.chunks, buf)
|
||||
return buf
|
||||
}
|
||||
|
||||
func (b *buffer) WriteTo(w io.Writer) (n int64, err error) {
|
||||
for _, c := range b.chunks {
|
||||
m, err := w.Write(c)
|
||||
n += int64(m)
|
||||
if err != nil {
|
||||
return n, err
|
||||
}
|
||||
}
|
||||
return n, nil
|
||||
}
|
Reference in New Issue
Block a user