Commit 7e1cfa74 authored by Rob Pike's avatar Rob Pike

Readn is a silly name when there's no n. Change to FullRead.

R=gri
DELTA=15  (0 added, 0 deleted, 15 changed)
OCL=27619
CL=27619
parent 2a1683a0
......@@ -19,7 +19,7 @@ func TestRunCat(t *testing.T) {
io.WriteString(cmd.Stdin, "hello, world\n");
cmd.Stdin.Close();
var buf [64]byte;
n, err1 := io.Readn(cmd.Stdout, &buf);
n, err1 := io.FullRead(cmd.Stdout, &buf);
if err1 != nil && err1 != io.ErrEOF {
t.Fatalf("reading from /bin/cat: %v", err1);
}
......@@ -38,7 +38,7 @@ func TestRunEcho(t *testing.T) {
t.Fatalf("opencmd /bin/echo: %v", err);
}
var buf [64]byte;
n, err1 := io.Readn(cmd.Stdout, &buf);
n, err1 := io.FullRead(cmd.Stdout, &buf);
if err1 != nil && err1 != io.ErrEOF {
t.Fatalf("reading from /bin/echo: %v", err1);
}
......
......@@ -142,7 +142,7 @@ func serveFileInternal(c *Conn, r *Request, name string, redirect bool) {
} else {
// read first chunk to decide between utf-8 text and binary
var buf [1024]byte;
n, err := io.Readn(f, &buf);
n, err := io.FullRead(f, &buf);
b := buf[0:n];
if isText(b) {
c.SetHeader("Content-Type", "text-plain; charset=utf-8");
......
......@@ -13,7 +13,7 @@ import (
"os";
)
// ErrEOF is the error returned by Readn and Copyn when they encounter EOF.
// ErrEOF is the error returned by FullRead and Copyn when they encounter EOF.
var ErrEOF = os.NewError("EOF")
// Read is the interface that wraps the basic Read method.
......@@ -70,8 +70,8 @@ func WriteString(w Write, s string) (n int, err os.Error) {
return w.Write(StringBytes(s))
}
// Readn reads r until the buffer buf is full, or until EOF or error.
func Readn(r Read, buf []byte) (n int, err os.Error) {
// FullRead reads r until the buffer buf is full, or until EOF or error.
func FullRead(r Read, buf []byte) (n int, err os.Error) {
n = 0;
for n < len(buf) {
nn, e := r.Read(buf[n:len(buf)]);
......@@ -89,18 +89,18 @@ func Readn(r Read, buf []byte) (n int, err os.Error) {
}
// Convert something that implements Read into something
// whose Reads are always Readn
// whose Reads are always FullReads
type fullRead struct {
r Read;
}
func (fr *fullRead) Read(p []byte) (n int, err os.Error) {
n, err = Readn(fr.r, p);
n, err = FullRead(fr.r, p);
return n, err
}
// MakeFullReader takes r, an implementation of Read, and returns an object
// that still implements Read but always calls Readn underneath.
// that still implements Read but always calls FullRead underneath.
func MakeFullReader(r Read) Read {
if fr, ok := r.(*fullRead); ok {
// already a fullRead
......
......@@ -23,7 +23,7 @@ func fetchGoogle(t *testing.T, fd net.Conn, network, addr string) {
n, err := fd.Write(req);
buf := make([]byte, 1000);
n, err = io.Readn(fd, buf);
n, err = io.FullRead(fd, buf);
if n < 1000 {
t.Errorf("fetchGoogle: short HTTP read from %s %s - %v", network, addr, err);
......
......@@ -46,7 +46,7 @@ func (f *file) readLine() (s string, ok bool) {
}
if len(f.data) < cap(f.data) {
ln := len(f.data);
n, err := io.Readn(f.file, f.data[ln:cap(f.data)]);
n, err := io.FullRead(f.file, f.data[ln:cap(f.data)]);
if n >= 0 {
f.data = f.data[0:ln+n];
}
......
......@@ -212,7 +212,7 @@ func readfile(name string, max int) (p []byte, err os.Error) {
return nil, e;
}
p = make([]byte, max);
n, err1 := io.Readn(f, p);
n, err1 := io.FullRead(f, p);
f.Close();
if err1 == nil { // too long
return nil, TimeZoneError{ "time: zone file too long: " + name };
......
......@@ -43,7 +43,7 @@ func readfile(filename string) ([]byte, OS.Error) {
return []byte{}, err;
}
var buf [1<<20]byte;
n, err1 := IO.Readn(f, &buf);
n, err1 := IO.FullRead(f, &buf);
f.Close();
if err1 == IO.ErrEOF {
err1 = nil;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment