You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
package interfaces
import (
"fmt""io""os"
)
// Copy copies data from in to out first directly,// then using a buffer. It also writes to stdoutfuncCopy(in io.ReadSeeker, out io.Writer) error {
// we write to out, but also Stdoutw:=io.MultiWriter(out, os.Stdout)
// a standard copy, this can be dangerous if there's a // lot of data in inif_, err:=io.Copy(w, in); err!=nil {
returnerr
}
in.Seek(0, 0)
// buffered write using 64 byte chunksbuf:=make([]byte, 64)
if_, err:=io.CopyBuffer(w, in, buf); err!=nil {
returnerr
}
// lets print a new linefmt.Println()
returnnil
}
package interfaces
import (
"io""os"
)
// PipeExample helps give some more examples of using io //interfacesfuncPipeExample() error {
// the pipe reader and pipe writer implement// io.Reader and io.Writerr, w:=io.Pipe()
// this needs to be run in a separate go routine// as it will block waiting for the reader// close at the end for cleanupgofunc() {
// for now we'll write something basic,// this could also be used to encode json// base64 encode, etc.w.Write([]byte("testn"))
w.Close()
}()
if_, err:=io.Copy(os.Stdout, r); err!=nil {
returnerr
}
returnnil
}