Go Package bytes

From NovaOrdis Knowledge Base
Revision as of 18:16, 5 January 2024 by Ovidiu (talk | contribs) (→‎Buffer)
Jump to navigation Jump to search

External

Internal

Buffer

A Buffer is a variable-sized buffer of bytes with Read and Write methods. The zero value for Buffer is an empty buffer ready to use. A Buffer does not have to be initialized and supports both Reader and Writer interface.

Conversion of a Buffer into a []byte:

var buffer bytes.Buffer
bytes := buffer.Bytes()

Why would I use an bytes.Buffer and not a byte slice?

Wrapping a byte[] into a Reader

[[Go_Package_io#Wrapping_a_[]byte_into_a_Reader|Wrapping a []byte into a Reader]]