]> Cypherpunks repositories - gostls13.git/commitdiff
io: rename Copyn to CopyN.
authorDavid Symonds <dsymonds@golang.org>
Fri, 30 Sep 2011 20:13:39 +0000 (13:13 -0700)
committerDavid Symonds <dsymonds@golang.org>
Fri, 30 Sep 2011 20:13:39 +0000 (13:13 -0700)
R=golang-dev, r
CC=golang-dev
https://golang.org/cl/5157045

src/cmd/gofix/Makefile
src/cmd/gofix/iocopyn.go [new file with mode: 0644]
src/cmd/gofix/iocopyn_test.go [new file with mode: 0644]
src/pkg/archive/tar/reader.go
src/pkg/http/fs.go
src/pkg/http/transport_test.go
src/pkg/io/io.go
src/pkg/io/io_test.go
src/pkg/mime/multipart/formdata.go
src/pkg/mime/multipart/multipart.go

index 8b0a2a77437ef5a4a368bdc3bb7ce216312b8407..7a2b7241f134d743baa8e8f64674e4924d4ddb19 100644 (file)
@@ -13,6 +13,7 @@ GOFILES=\
        httpheaders.go\
        httpserver.go\
        imagenew.go\
+       iocopyn.go\
        main.go\
        math.go\
        netdial.go\
diff --git a/src/cmd/gofix/iocopyn.go b/src/cmd/gofix/iocopyn.go
new file mode 100644 (file)
index 0000000..f404460
--- /dev/null
@@ -0,0 +1,40 @@
+// Copyright 2011 The Go Authors.  All rights reserved.
+// Use of this source code is governed by a BSD-style
+// license that can be found in the LICENSE file.
+
+package main
+
+import (
+       "go/ast"
+)
+
+var ioCopyNFix = fix{
+       "iocopyn",
+       ioCopyN,
+       `Rename io.Copyn to io.CopyN.
+
+http://codereview.appspot.com/5157045
+`,
+}
+
+func init() {
+       register(ioCopyNFix)
+}
+
+func ioCopyN(f *ast.File) bool {
+       if !imports(f, "io") {
+               return false
+       }
+
+       fixed := false
+       walk(f, func(n interface{}) {
+               if expr, ok := n.(ast.Expr); ok {
+                       if isPkgDot(expr, "io", "Copyn") {
+                               expr.(*ast.SelectorExpr).Sel.Name = "CopyN"
+                               fixed = true
+                               return
+                       }
+               }
+       })
+       return fixed
+}
diff --git a/src/cmd/gofix/iocopyn_test.go b/src/cmd/gofix/iocopyn_test.go
new file mode 100644 (file)
index 0000000..2734776
--- /dev/null
@@ -0,0 +1,37 @@
+// Copyright 2011 The Go Authors.  All rights reserved.
+// Use of this source code is governed by a BSD-style
+// license that can be found in the LICENSE file.
+
+package main
+
+func init() {
+       addTestCases(ioCopyNTests)
+}
+
+var ioCopyNTests = []testCase{
+       {
+               Name: "io.CopyN.0",
+               In: `package main
+
+import (
+       "io"
+)
+
+func f() {
+       io.Copyn(dst, src)
+       foo.Copyn(dst, src)
+}
+`,
+               Out: `package main
+
+import (
+       "io"
+)
+
+func f() {
+       io.CopyN(dst, src)
+       foo.Copyn(dst, src)
+}
+`,
+       },
+}
index 45d95c3df299feacdd74b2b4cad9ed8609e80aed..12de2ada0830140d012eba5c1b0fcfab0dd5eca4 100644 (file)
@@ -94,7 +94,7 @@ func (tr *Reader) skipUnread() {
                        return
                }
        }
-       _, tr.err = io.Copyn(ioutil.Discard, tr.r, nr)
+       _, tr.err = io.CopyN(ioutil.Discard, tr.r, nr)
 }
 
 func (tr *Reader) verifyChecksum(header []byte) bool {
index 2c7c636fda0b24fdbf3e89b4b7c88c23dc02d086..6d716654a239d1032234ff873506a1ef184dd441 100644 (file)
@@ -219,7 +219,7 @@ func serveFile(w ResponseWriter, r *Request, fs FileSystem, name string, redirec
        w.WriteHeader(code)
 
        if r.Method != "HEAD" {
-               io.Copyn(w, f, size)
+               io.CopyN(w, f, size)
        }
 }
 
index eafde7f8995a12d895b0261cc618f42af9fb46da..b9ae7a36857caa6fd9f742abdc039939c1ccc1ee 100644 (file)
@@ -474,7 +474,7 @@ func TestTransportGzip(t *testing.T) {
                gz, _ := gzip.NewWriter(w)
                gz.Write([]byte(testString))
                if req.FormValue("body") == "large" {
-                       io.Copyn(gz, rand.Reader, nRandBytes)
+                       io.CopyN(gz, rand.Reader, nRandBytes)
                }
                gz.Close()
        }))
index 1fdf3470634cd221bf1a13e9c59279f2463e36a4..55206348e42cddb25b8febe5f9ea4c9842264849 100644 (file)
@@ -256,15 +256,15 @@ func ReadFull(r Reader, buf []byte) (n int, err os.Error) {
        return ReadAtLeast(r, buf, len(buf))
 }
 
-// Copyn copies n bytes (or until an error) from src to dst.
+// CopyN copies n bytes (or until an error) from src to dst.
 // It returns the number of bytes copied and the earliest
 // error encountered while copying.  Because Read can
 // return the full amount requested as well as an error
-// (including os.EOF), so can Copyn.
+// (including os.EOF), so can CopyN.
 //
 // If dst implements the ReaderFrom interface,
 // the copy is implemented by calling dst.ReadFrom(src).
-func Copyn(dst Writer, src Reader, n int64) (written int64, err os.Error) {
+func CopyN(dst Writer, src Reader, n int64) (written int64, err os.Error) {
        // If the writer has a ReadFrom method, use it to do the copy.
        // Avoids a buffer allocation and a copy.
        if rt, ok := dst.(ReaderFrom); ok {
index 7449dcf896e921b0d03c7803af0d7200181337d3..f1b23e9461bbe1d7d3c56ddb2910a1b6567c6c22 100644 (file)
@@ -19,7 +19,7 @@ type Buffer struct {
        WriterTo   // conflicts with and hides bytes.Buffer's WriterTo.
 }
 
-// Simple tests, primarily to verify the ReadFrom and WriteTo callouts inside Copy and Copyn.
+// Simple tests, primarily to verify the ReadFrom and WriteTo callouts inside Copy and CopyN.
 
 func TestCopy(t *testing.T) {
        rb := new(Buffer)
@@ -51,33 +51,33 @@ func TestCopyWriteTo(t *testing.T) {
        }
 }
 
-func TestCopyn(t *testing.T) {
+func TestCopyN(t *testing.T) {
        rb := new(Buffer)
        wb := new(Buffer)
        rb.WriteString("hello, world.")
-       Copyn(wb, rb, 5)
+       CopyN(wb, rb, 5)
        if wb.String() != "hello" {
-               t.Errorf("Copyn did not work properly")
+               t.Errorf("CopyN did not work properly")
        }
 }
 
-func TestCopynReadFrom(t *testing.T) {
+func TestCopyNReadFrom(t *testing.T) {
        rb := new(Buffer)
        wb := new(bytes.Buffer) // implements ReadFrom.
        rb.WriteString("hello")
-       Copyn(wb, rb, 5)
+       CopyN(wb, rb, 5)
        if wb.String() != "hello" {
-               t.Errorf("Copyn did not work properly")
+               t.Errorf("CopyN did not work properly")
        }
 }
 
-func TestCopynWriteTo(t *testing.T) {
+func TestCopyNWriteTo(t *testing.T) {
        rb := new(bytes.Buffer) // implements WriteTo.
        wb := new(Buffer)
        rb.WriteString("hello, world.")
-       Copyn(wb, rb, 5)
+       CopyN(wb, rb, 5)
        if wb.String() != "hello" {
-               t.Errorf("Copyn did not work properly")
+               t.Errorf("CopyN did not work properly")
        }
 }
 
@@ -89,30 +89,30 @@ func (w *noReadFrom) Write(p []byte) (n int, err os.Error) {
        return w.w.Write(p)
 }
 
-func TestCopynEOF(t *testing.T) {
+func TestCopyNEOF(t *testing.T) {
        // Test that EOF behavior is the same regardless of whether
-       // argument to Copyn has ReadFrom.
+       // argument to CopyN has ReadFrom.
 
        b := new(bytes.Buffer)
 
-       n, err := Copyn(&noReadFrom{b}, strings.NewReader("foo"), 3)
+       n, err := CopyN(&noReadFrom{b}, strings.NewReader("foo"), 3)
        if n != 3 || err != nil {
-               t.Errorf("Copyn(noReadFrom, foo, 3) = %d, %v; want 3, nil", n, err)
+               t.Errorf("CopyN(noReadFrom, foo, 3) = %d, %v; want 3, nil", n, err)
        }
 
-       n, err = Copyn(&noReadFrom{b}, strings.NewReader("foo"), 4)
+       n, err = CopyN(&noReadFrom{b}, strings.NewReader("foo"), 4)
        if n != 3 || err != os.EOF {
-               t.Errorf("Copyn(noReadFrom, foo, 4) = %d, %v; want 3, EOF", n, err)
+               t.Errorf("CopyN(noReadFrom, foo, 4) = %d, %v; want 3, EOF", n, err)
        }
 
-       n, err = Copyn(b, strings.NewReader("foo"), 3) // b has read from
+       n, err = CopyN(b, strings.NewReader("foo"), 3) // b has read from
        if n != 3 || err != nil {
-               t.Errorf("Copyn(bytes.Buffer, foo, 3) = %d, %v; want 3, nil", n, err)
+               t.Errorf("CopyN(bytes.Buffer, foo, 3) = %d, %v; want 3, nil", n, err)
        }
 
-       n, err = Copyn(b, strings.NewReader("foo"), 4) // b has read from
+       n, err = CopyN(b, strings.NewReader("foo"), 4) // b has read from
        if n != 3 || err != os.EOF {
-               t.Errorf("Copyn(bytes.Buffer, foo, 4) = %d, %v; want 3, EOF", n, err)
+               t.Errorf("CopyN(bytes.Buffer, foo, 4) = %d, %v; want 3, EOF", n, err)
        }
 }
 
index 91404d6f41c8b9848c515d803a4814ccf0b096d8..d114bfa9b433f82fa029c026c6fdc49380aaa706 100644 (file)
@@ -47,7 +47,7 @@ func (r *Reader) ReadForm(maxMemory int64) (f *Form, err os.Error) {
 
                if filename == "" {
                        // value, store as string in memory
-                       n, err := io.Copyn(&b, p, maxValueBytes)
+                       n, err := io.CopyN(&b, p, maxValueBytes)
                        if err != nil && err != os.EOF {
                                return nil, err
                        }
@@ -64,7 +64,7 @@ func (r *Reader) ReadForm(maxMemory int64) (f *Form, err os.Error) {
                        Filename: filename,
                        Header:   p.Header,
                }
-               n, err := io.Copyn(&b, p, maxMemory+1)
+               n, err := io.CopyN(&b, p, maxMemory+1)
                if err != nil && err != os.EOF {
                        return nil, err
                }
index f2b507220c1af7feb19ccfd500b1890e0c65a9ce..d36e9e91b8f9a2fac918dbd79f0ede22ebfb3edc 100644 (file)
@@ -146,7 +146,7 @@ func (bp *Part) Read(p []byte) (n int, err os.Error) {
                return 0, io.ErrUnexpectedEOF
        }
        if nCopy > 0 {
-               if _, err := io.Copyn(bp.buffer, bp.mr.bufReader, int64(nCopy)); err != nil {
+               if _, err := io.CopyN(bp.buffer, bp.mr.bufReader, int64(nCopy)); err != nil {
                        return 0, err
                }
        }