Skip to content

Instantly share code, notes, and snippets.

@yakuter
Created February 15, 2024 20:56
Show Gist options
  • Save yakuter/d74659ace1bc596fc3469f57a026ae77 to your computer and use it in GitHub Desktop.
Save yakuter/d74659ace1bc596fc3469f57a026ae77 to your computer and use it in GitHub Desktop.
Copy and Movement 10
package main
import (
"fmt"
"io"
"strings"
)
func main() {
reader := strings.NewReader("Test")
buf := make([]byte, 8)
// Wrong: Assuming exactly 8 bytes will be read
n, err := reader.Read(buf)
if err != nil {
fmt.Println("Failed to read:", err)
return
}
fmt.Printf("Read data: %s\n", string(buf[:n]))
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment