| 1 | package fsutilscip-go gomod github.com/tonistiigi/fsutil . `github.com/tonistiigi/fsutil`/ |
| 2 | |
| 3 | import ( |
| 4 | "ioscip-go gomod github.com/golang/go/src go1.21 io/" |
| 5 | ) |
| 6 | |
| 7 | const chunkSizescip-go gomod github.com/tonistiigi/fsutil . `github.com/tonistiigi/fsutil`/chunkSize. = 32 * 1024 |
| 8 | |
| 9 | type bufferscip-go gomod github.com/tonistiigi/fsutil . `github.com/tonistiigi/fsutil`/buffer# struct { |
| 10 | chunksscip-go gomod github.com/tonistiigi/fsutil . `github.com/tonistiigi/fsutil`/buffer#chunks. [][]byte |
| 11 | } |
| 12 | |
| 13 | func (b *bufferscip-go gomod github.com/tonistiigi/fsutil . `github.com/tonistiigi/fsutil`/buffer#) allocscip-go gomod github.com/tonistiigi/fsutil . `github.com/tonistiigi/fsutil`/buffer#alloc().(n int) []byte { |
| 14 | if n > chunkSizescip-go gomod github.com/tonistiigi/fsutil . `github.com/tonistiigi/fsutil`/chunkSize. { |
| 15 | buf := make([]byte, n) |
| 16 | b.chunksscip-go gomod github.com/tonistiigi/fsutil . `github.com/tonistiigi/fsutil`/buffer#chunks. = append(b.chunksscip-go gomod github.com/tonistiigi/fsutil . `github.com/tonistiigi/fsutil`/buffer#chunks., buf) |
| 17 | return buf |
| 18 | } |
| 19 | |
| 20 | if len(b.chunksscip-go gomod github.com/tonistiigi/fsutil . `github.com/tonistiigi/fsutil`/buffer#chunks.) != 0 { |
| 21 | lastChunk := b.chunksscip-go gomod github.com/tonistiigi/fsutil . `github.com/tonistiigi/fsutil`/buffer#chunks.[len(b.chunksscip-go gomod github.com/tonistiigi/fsutil . `github.com/tonistiigi/fsutil`/buffer#chunks.)-1] |
| 22 | l := len(lastChunk) |
| 23 | if l+n <= cap(lastChunk) { |
| 24 | lastChunk = lastChunk[:l+n] |
| 25 | b.chunksscip-go gomod github.com/tonistiigi/fsutil . `github.com/tonistiigi/fsutil`/buffer#chunks.[len(b.chunksscip-go gomod github.com/tonistiigi/fsutil . `github.com/tonistiigi/fsutil`/buffer#chunks.)-1] = lastChunk |
| 26 | return lastChunk[l : l+n] |
| 27 | } |
| 28 | } |
| 29 | |
| 30 | buf := make([]byte, n, chunkSizescip-go gomod github.com/tonistiigi/fsutil . `github.com/tonistiigi/fsutil`/chunkSize.) |
| 31 | b.chunksscip-go gomod github.com/tonistiigi/fsutil . `github.com/tonistiigi/fsutil`/buffer#chunks. = append(b.chunksscip-go gomod github.com/tonistiigi/fsutil . `github.com/tonistiigi/fsutil`/buffer#chunks., buf) |
| 32 | return buf |
| 33 | } |
| 34 | |
| 35 | func (b *bufferscip-go gomod github.com/tonistiigi/fsutil . `github.com/tonistiigi/fsutil`/buffer#) WriteToscip-go gomod github.com/tonistiigi/fsutil . `github.com/tonistiigi/fsutil`/buffer#WriteTo().(w ioscip-go gomod github.com/golang/go/src go1.21 io/.Writerscip-go gomod github.com/golang/go/src go1.21 io/Writer#) (n int64, err error) { |
| 36 | for _, c := range b.chunksscip-go gomod github.com/tonistiigi/fsutil . `github.com/tonistiigi/fsutil`/buffer#chunks. { |
| 37 | m, err := w.Writescip-go gomod github.com/golang/go/src go1.21 io/Writer#Write().(c) |
| 38 | n += int64(m) |
| 39 | if err != nil { |
| 40 | return n, err |
| 41 | } |
| 42 | } |
| 43 | return n, nil |
| 44 | } |