-
Notifications
You must be signed in to change notification settings - Fork 18k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
io: Copyn slow- and fast-path asymmetry #1383
Labels
Comments
When the io.Copyn destination implements a ReaderFrom interface, the number of bytes copied is limited to n by the LimitReader. For example, package main import ( "bytes" "fmt" "io" ) func main() { pfx := "01234567" sfx := "89" r := bytes.NewBuffer([]byte(pfx + sfx)) w := bytes.NewBuffer(nil) n, err := io.Copyn(w, r, int64(len(pfx))) // 8 <nil> fmt.Println(n, err) // true true fmt.Println(r.String() == sfx, w.String() == pfx) } |
In _, err = Copyn(dst, src, N) notice how the meaning of err varies depending on dst: 1) if dst satisfies ReaderFrom, err == nil means N bytes have or have not been copied. 2) if dst does not satisfy ReaderFrom, err == nil means N bytes have been copied. Consider below program; its output is: 3 <nil> 3 <nil> 3 EOF 3 <nil> while I was expecting more consistent: 3 <nil> 3 <nil> 3 EOF 3 EOF package main import ( "bufio" "bytes" "io" "os" "strings" "fmt" ) func main() { var w io.Writer w = bufio.NewWriter(os.Stdout) n, err := io.Copyn(w, strings.NewReader("foo"), 3) // 3 <nil> fmt.Println(n, err) w = bytes.NewBuffer(nil) n, err = io.Copyn(w, strings.NewReader("foo"), 3) // 3 <nil> fmt.Println(n, err) w = bufio.NewWriter(os.Stdout) n, err = io.Copyn(w, strings.NewReader("foo"), 4) // 3 EOF fmt.Println(n, err) w = bytes.NewBuffer(nil) n, err = io.Copyn(w, strings.NewReader("foo"), 4) // 3 <nil> fmt.Println(n, err) } |
3821044 Owner changed to r...@golang.org. Status changed to Started. |
This issue was closed by revision 0f26608. Status changed to Fixed. |
This issue was closed.
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
The text was updated successfully, but these errors were encountered: