Skip to content

Instantly share code, notes, and snippets.

@yakuter
Created February 15, 2024 21:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save yakuter/154152f4e743bcac5f80e4a8ec4cb484 to your computer and use it in GitHub Desktop.
Save yakuter/154152f4e743bcac5f80e4a8ec4cb484 to your computer and use it in GitHub Desktop.
Copy and Movement 11
package main
import (
"fmt"
"io"
"strings"
)
func main() {
reader := strings.NewReader("This is a test message.")
buf := make([]byte, 8)
for {
n, err := reader.Read(buf)
if n > 0 {
fmt.Printf("Read data: %s\n", string(buf[:n]))
}
if err == io.EOF {
break // End of the file. Exit from loop.
}
if err != nil {
fmt.Println("Failed to read:", err)
return
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment