Home > Back-end >  What's the difference between io.Copy and io.CopyBuffer?
What's the difference between io.Copy and io.CopyBuffer?

Time:10-02

In the documentation of io.CopyBuffer it states:

CopyBuffer is identical to Copy except that it stages through the provided buffer (if one is required) rather than allocating a temporary one.

Does that mean that io.CopyBuffer will copy first to buffer and then into destination making less calls to source Write?

CodePudding user response:

CopyBuffer let’s you allocate your own buffer. It is otherwise the same as Copy. If you look at Copy, it just calls CopyBuffer.

CopyBuffer let's you choose your own buffer size. io.Copy by default uses a 32K buffer. If you know your copy will be large, a larger buffer may be more performant. In addition to allowing the caller to control the size of the buffer, a caller can use a single buffer for multiple copy operations.

  •  Tags:  
  • goio
  • Related