Benjamin,
On Sat, Aug 17, 2013 at 3:49 PM, Benjamin Measures
<
saint....@gmail.com> wrote:
> On Saturday, 17 August 2013 19:03:28 UTC+1, Mitchell Hashimoto wrote:
>>
>> There is a bytes.Reader for turning a raw []byte into an io.Reader. Why is
>> there no equivalent for io.Writer?
>
>
> What would that mean? A writeTo on one side is the same as a readFrom on the
> other.
It means I can use a []byte as an io.Writer. Having a ReadFrom/WriteTo
implements other interfaces which simply don't satisfy this.
I realize it wouldn't be difficult by any means. It is an easy handful
of lines to write to implement it for []byte. My question was mostly
why doesn't the pair exist in the standard library or if there was a
better way to do what I'm doing.
>
>>
>> The reasoning is I want to copy an io.Reader where I know the length (so
>> io.CopyN) into a []byte. Thoughts?
>
>
> Just io.Read(p []byte) - it reads up to len(p) bytes into p:
>
http://golang.org/pkg/io/#Reader
It reads UP TO len(p). If it reads a part and it would start blocking
it might return what it has "so far". I would still have to write a
helper function to copy it all. What I want is a "read until EOF"
(which is io.Copy), so I want an io.Writer implementation so I can use
it on the left side of io.Copy.
For now I've just used "bytes.NewBuffer" since I know exactly how many
bytes will go into there.
Best,
Mitchell
>
> --
> 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/FB4OtiRm28E/unsubscribe.
> To unsubscribe from this group and all its topics, send an email to
>
golang-nuts...@googlegroups.com.
> For more options, visit
https://groups.google.com/groups/opt_out.