33 lines
625 B
Go
33 lines
625 B
Go
|
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
|
||
|
}
|
||
|
}
|
||
|
}
|