Go Package bytes: Difference between revisions
Jump to navigation
Jump to search
No edit summary |
|||
(2 intermediate revisions by the same user not shown) | |||
Line 5: | Line 5: | ||
=Internal= | =Internal= | ||
* [[ | * [[Go_Language_Modularization#bytes|Standard Library]] | ||
=<tt>Buffer</tt>= | =<tt>Buffer</tt>= | ||
Line 20: | Line 20: | ||
</pre> | </pre> | ||
<font color= | <font color=darkkhaki>Why would I use an bytes.Buffer and not a byte slice?</font> | ||
=Wrapping a <tt>byte[]</tt> into a <tt>Reader</tt>= | |||
{{Internal|Go_Package_io#WBSR|Wrapping a <tt>[]byte</tt> into a <tt>Reader</tt>}} |
Latest revision as of 18:17, 5 January 2024
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?