cloudflare/cloudflared

Public

mirrored fromhttps://github.com/cloudflare/cloudflaredAvailable

CodeCommitsIssuesPull requestsActionsInsightsSecurity
2026.5.0

Branches

Tags

  • No tags available.
0Branches0Tags
Go to file
Add file
Code

Clone

HTTPS

Download ZIP

cfio/copy.go

27lines · modecode

1package cfio
2
3import (
4 "io"
5 "sync"
6)
7
8const defaultBufferSize = 16 * 1024
9
10var bufferPool = sync.Pool{
11 New: func() interface{} {
12 return make([]byte, defaultBufferSize)
13 },
14}
15
16func Copy(dst io.Writer, src io.Reader) (written int64, err error) {
17 _, okWriteTo := src.(io.WriterTo)
18 _, okReadFrom := dst.(io.ReaderFrom)
19 var buffer []byte = nil
20
21 if !(okWriteTo || okReadFrom) {
22 buffer = bufferPool.Get().([]byte)
23 defer bufferPool.Put(buffer)
24 }
25
26 return io.CopyBuffer(dst, src, buffer)
27}
28