Read lets you build pipelines, it involves fewer expensive allocations
(ie. you might not want to use ReadFull in the hot path of an important
project), you could use read to read into a slice at different points,
or not read the entirety of an expensive document into memory all at
once, you can implement buffering on top of it, etc.

It's probably pretty rare that you actually want to use ReadFull, or at
least, I don't find myself reaching for it very often.

—Sam


On Tue, Jun 9, 2020, at 12:51, Amit Lavon wrote:
> Thank you!! io.ReadFull is just what I needed (and what I actually
> expected from Reader.Read). Why would I ever use Reader.Read rather
> than ReadFull?
>
> On Tue, Jun 9, 2020 at 6:11 PM Brian Candler
> <b.cand...@pobox.com> wrote:
> > There is io.ReadFull <https://golang.org/pkg/io/#ReadFull> if you
> > want to read as much as it can into the preallocated buffer; you'll
> > get io.ErrUnexpectedEOF if it's less than this.
> > https://play.golang.org/p/gIAX046vNvW
> >
> > There is ioutil.ReadAll <https://golang.org/pkg/io/ioutil/#ReadAll>
> > if you want to allocate memory to read the entire stream into a
> > single buffer (assuming you have enough RAM)
> > https://play.golang.org/p/Pg17S6A74SN
>
> >  --
> >  You received this message because you are subscribed to a topic in
> >  the Google Groups "golang-nuts" group. To unsubscribe from this
> >  topic, visit
> >  https://groups.google.com/d/topic/golang-nuts/u-wNH3NyMHo/unsubscribe.
> >  To unsubscribe from this group and all its topics, send an email to
> >  golang-nuts+unsubscr...@googlegroups.com. To view this discussion
> >  on the web visit
> >  
> > https://groups.google.com/d/msgid/golang-nuts/8ff054df-218c-4d52-8984-83b1c4444ed9o%40googlegroups.com
> >  
> > <https://groups.google.com/d/msgid/golang-nuts/8ff054df-218c-4d52-8984-83b1c4444ed9o%40googlegroups.com?utm_medium=email&utm_source=footer>
> >  .
>
>  --
>  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+unsubscr...@googlegroups.com. To view this discussion on the web
>  visit
>  
> https://groups.google.com/d/msgid/golang-nuts/CAPTkDQVudE24DF6tWBO6yFTyF4TgZOopEfjnqZXLhVphp8SBwQ%40mail.gmail.com
>  
> <https://groups.google.com/d/msgid/golang-nuts/CAPTkDQVudE24DF6tWBO6yFTyF4TgZOopEfjnqZXLhVphp8SBwQ%40mail.gmail.com?utm_medium=email&utm_source=footer>
>  .

-- 
Sam Whited

-- 
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+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/b203a7e4-0275-46c5-9b1e-05ed7a140e8e%40www.fastmail.com.

Reply via email to