bufio.NewReader vs bytes.buffer

744 views
Skip to first unread message

WALID BELRHALMIA

unread,
Sep 20, 2015, 2:48:50 AM9/20/15
to golang-nuts
what is the ddifference between bufio.NewReader and bufio.NewWriter   that implement a buffer for the reader or writer . and bytes.buffer 

Kiki Sugiaman

unread,
Sep 20, 2015, 3:03:46 AM9/20/15
to golan...@googlegroups.com
In a nutshell: you can only write into a bufio.Writer and read from a
bufio.Reader. You can do both to a buffer.


On 20/09/15 16:48, WALID BELRHALMIA wrote:
> what is the ddifference between bufio.NewReader and bufio.NewWriter
> that implement a buffer for the reader or writer . and bytes.buffer
> --
> You received this message because you are subscribed to the Google
> Groups "golang-nuts" group.
> To unsubscribe from this group and stop receiving emails from it, send
> an email to golang-nuts...@googlegroups.com
> <mailto:golang-nuts...@googlegroups.com>.
> For more options, visit https://groups.google.com/d/optout.

Jesse McNelis

unread,
Sep 20, 2015, 3:20:06 AM9/20/15
to WALID BELRHALMIA, golang-nuts
On Sun, Sep 20, 2015 at 4:48 PM, WALID BELRHALMIA <wbelr...@gmail.com> wrote:
> what is the ddifference between bufio.NewReader and bufio.NewWriter that
> implement a buffer for the reader or writer . and bytes.buffer

bytes.Buffer is an in-memory buffer that you can Read() and Write()
to, it's just like an in-memory file.

The bufio package is used for wrapping io.Readers and io.Writers and
buffers data to reduce the number of Read() or Write() calls to the
underlying io.Reader or io.Writer.

eg. you can wrap an os.File in an bufio.NewReader so that not every
Read() needs to hit the disk allowing you to efficiently make Read()
calls for small numbers of bytes.
Reply all
Reply to author
Forward
0 new messages