diff --git a/3methods/readers.go b/3methods/readers.go new file mode 100644 index 0000000..714e405 --- /dev/null +++ b/3methods/readers.go @@ -0,0 +1,32 @@ +package main + +import ( + "fmt" + "io" + "strings" +) + +func main() { + fmt.Println("the io package specifies io.Reader interface, which represents the end of a stream of data") + + r := strings.NewReader("📩⍼ ꜜx Hello, Your Computer has virus .d") + // specifies new Reader + + b := make([]byte, 4) + // think this like a bucket for temporary inputs + + for { + n, err := r.Read(b) + // Read gets Reader (r) and gets next b byte in it + // returns n (number of bytes populated) + // and err (error, EOF for example) + + fmt.Println(n, err, b) + fmt.Println(b[:n]) + fmt.Printf("%s\n\n", b[:n]) + + if err == io.EOF { + break + } + } +}