This commit is contained in:
Aliberk Sandıkçı 2023-07-31 10:05:18 +03:00
parent 4b524656ed
commit 728c487b76
Signed by: asandikci
GPG key ID: 25C67A03B5666BC1

32
3methods/readers.go Normal file
View file

@ -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
}
}
}