>From the docs <http://godoc.org/io#Reader>:

Read reads up to len(p) bytes into p.


This lets the caller of Read manage the allocation and re-use of p. It also 
means your Read method has to work within the confines of whatever p you 
are given. If the data being read is larger than p, then the Read 
implementation must keep track of how much of the data has been read so 
far, and put the next part into p. 

On Sunday, June 25, 2017 at 8:39:58 PM UTC+2, 苏聪厚 wrote:
>
> package main
>
> import (
>    "io"
>    "log"
>    "os"
> )
>
> type test struct {
>    name string
> }
>
> func (a *test) Read(p []byte) (int, error) {
>
>     var size int
>    for {
>        // I want to  put large data to response the read ; some data 
> whatever I want ...
>
>         size = size + 102400
>        // condition  to break
>        break
>    }
>
>     return size, nil
> }
>
> func main() {
>    r := &test{name: "test"}
>    if _, err := io.Copy(os.Stdout, r); err != nil {
>        log.Fatal(err)
>    }
> }
>
>
> How Read method get its data , I do not know where my data should be put , 
> the method just return int 
>
>

-- 
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.
For more options, visit https://groups.google.com/d/optout.

Reply via email to