Use read and expand the buffer as needed (or write the chunks to a file). If at 
the end it is all going to be in memory, you might as well start with the very 
large buffer. There is nothing special about Go in this regard - it’s standard 
IO processing. 

> On Dec 29, 2019, at 9:21 AM, Ron Wahler <ron.wah...@gmail.com> wrote:
> 
> 
> Jake,
> 
> Thanks for the reply. Csrc.Read is what I was referring to as the connection 
> standard read, should not have used the words "standard read" sorry about 
> that. The problem I am trying to solve is reading an unknown amount of byte 
> data.  I am trying to understand what triggers the Csrc.Read(buf) to return 
> when I send say 3 bytes to it with a client, I also keep the connection open 
> and send a few bytes of characters with the netcat tool, the Csrc.Read 
> returns, but the snip it below that with ReadAll does not return. I am trying 
> to understand the underlying behavior of what triggers a return with the data 
> in these two calls ?
> 
> on this read :
> 
> Csrc net.Conn
> 
> 
>  buf := make([]byte, 1024*32)
> 
>  // READ FROM CLIENT
> 
>  nBytes, err := Csrc.Read(buf)
> 
> 
> 
> Csrc.Read(buf)  returns with a few bytes that I send to it.  It does not wait 
> for the entire allocated buf size to return. This works great, but I am 
> looking for a way to not preallocate a large buffer.
> 
> 
> 
> I am prototyping with ReadAll, see the following snip it, but when I send a 
> few bytes to this call with a client, it does not return. The documentation 
> is saying it may be  looking for an EOF which I do not send.
> 
> 
> 
>   buf, read_err := ioutil.ReadAll(Csrc)
> 
> 
> 
> 
> 
> thanks,
> 
> Ron
> 
> 
> 
> 
> 
> 
> On Friday, December 27, 2019 at 5:11:42 PM UTC-7, Ron Wahler wrote:
>> 
>> I am looking for a net.conn standard read that would return a data buffer 
>> the exact size of the read. I am trying to read an unknown amount of byte 
>> data from the connection. With the read i am using I am required to 
>> pre-allocate a buffer and pass that buffer to the read. I am looking for a 
>> read that works more like  the ReadString , but is for a byte slice.
>> 
>> // I want something similar to this read that returns the read string into 
>> the message string.
>>  message, err := bufio.NewReader(ServerConn).ReadString('\n')
>> 
>>                 if ( err != nil ){
>> 
>>                         fmt.Println("RELAY: ERROR:  Reg Message read err:", 
>> err)
>> 
>>                         return 
>> 
>>                 }
>> 
>> 
>> 
>> 
>> 
>> // had to preallocate a buffer, but I want a read to return me a buffer so I 
>> don't have to guess how big to make it.
>> 
>>  buf := make([]byte, 1024*32)
>> 
>>  // READ FROM CLIENT
>> 
>>  nBytes, err := Csrc.Read(buf)
>> 
>> 
>> 
>> 
>> 
>> Is this not possible, I have not seen any examples that would indicate that 
>> there is a standard library that would do something like what I am looking 
>> for.
>> 
>> 
>> 
>> thanks,
>> 
>> Ron
>> 
> 
> -- 
> 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/cd1f26d6-72aa-4239-83f2-18dc6220c2db%40googlegroups.com.

-- 
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/BFCC2BF2-73AA-4539-B833-5CBDF595CC7E%40ix.netcom.com.

Reply via email to