aboutsummaryrefslogtreecommitdiff
path: root/src/lib/io
diff options
context:
space:
mode:
authorRob Pike <r@golang.org>2009-05-08 11:22:57 -0700
committerRob Pike <r@golang.org>2009-05-08 11:22:57 -0700
commitc8b47c6fceeb249ab9e6f39503615ebe2ea205ce (patch)
tree2affd4955742b1bde18daf6a1f053e148c7b9838 /src/lib/io
parentdf46b3342ce54129af59e30ff6d9708347f61c75 (diff)
downloadgo-c8b47c6fceeb249ab9e6f39503615ebe2ea205ce.tar.xz
Name change to improve embeddability:
io.Read->io.Reader io.Write,Close,etc.->io.Writer,Closer etc. R=rsc DELTA=190 (0 added, 0 deleted, 190 changed) OCL=28525 CL=28535
Diffstat (limited to 'src/lib/io')
-rw-r--r--src/lib/io/io.go56
-rw-r--r--src/lib/io/pipe.go6
-rw-r--r--src/lib/io/pipe_test.go22
3 files changed, 42 insertions, 42 deletions
diff --git a/src/lib/io/io.go b/src/lib/io/io.go
index 5036e326a6..bb6381099c 100644
--- a/src/lib/io/io.go
+++ b/src/lib/io/io.go
@@ -16,44 +16,44 @@ import (
// 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.
-type Read interface {
+// Reader is the interface that wraps the basic Read method.
+type Reader interface {
Read(p []byte) (n int, err os.Error);
}
-// Write is the interface that wraps the basic Write method.
-type Write interface {
+// Writer is the interface that wraps the basic Write method.
+type Writer interface {
Write(p []byte) (n int, err os.Error);
}
-// Close is the interface that wraps the basic Close method.
-type Close interface {
+// Closer is the interface that wraps the basic Close method.
+type Closer interface {
Close() os.Error;
}
// ReadWrite is the interface that groups the basic Read and Write methods.
-type ReadWrite interface {
- Read;
- Write;
+type ReadWriter interface {
+ Reader;
+ Writer;
}
-// ReadClose is the interface that groups the basic Read and Close methods.
-type ReadClose interface {
- Read;
- Close;
+// ReadCloser is the interface that groups the basic Read and Close methods.
+type ReadCloser interface {
+ Reader;
+ Closer;
}
-// WriteClose is the interface that groups the basic Write and Close methods.
-type WriteClose interface {
- Write;
- Close;
+// WriteCloser is the interface that groups the basic Write and Close methods.
+type WriteCloser interface {
+ Writer;
+ Closer;
}
-// ReadWriteClose is the interface that groups the basic Read, Write and Close methods.
-type ReadWriteClose interface {
- Read;
- Write;
- Close;
+// ReadWriteCloser is the interface that groups the basic Read, Write and Close methods.
+type ReadWriteCloser interface {
+ Reader;
+ Writer;
+ Closer;
}
// Convert a string to an array of bytes for easy marshaling.
@@ -66,12 +66,12 @@ func StringBytes(s string) []byte {
}
// WriteString writes the contents of the string s to w, which accepts an array of bytes.
-func WriteString(w Write, s string) (n int, err os.Error) {
+func WriteString(w Writer, s string) (n int, err os.Error) {
return w.Write(StringBytes(s))
}
// 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) {
+func FullRead(r Reader, buf []byte) (n int, err os.Error) {
n = 0;
for n < len(buf) {
nn, e := r.Read(buf[n:len(buf)]);
@@ -91,7 +91,7 @@ func FullRead(r Read, buf []byte) (n int, err os.Error) {
// Convert something that implements Read into something
// whose Reads are always FullReads
type fullRead struct {
- r Read;
+ r Reader;
}
func (fr *fullRead) Read(p []byte) (n int, err os.Error) {
@@ -101,7 +101,7 @@ func (fr *fullRead) Read(p []byte) (n int, err os.Error) {
// MakeFullReader takes r, an implementation of Read, and returns an object
// that still implements Read but always calls FullRead underneath.
-func MakeFullReader(r Read) Read {
+func MakeFullReader(r Reader) Reader {
if fr, ok := r.(*fullRead); ok {
// already a fullRead
return r
@@ -111,7 +111,7 @@ func MakeFullReader(r Read) Read {
// Copy n copies n bytes (or until EOF is reached) from src to dst.
// It returns the number of bytes copied and the error, if any.
-func Copyn(src Read, dst Write, n int64) (written int64, err os.Error) {
+func Copyn(src Reader, dst Writer, n int64) (written int64, err os.Error) {
buf := make([]byte, 32*1024);
for written < n {
l := len(buf);
@@ -147,7 +147,7 @@ func Copyn(src Read, dst Write, n int64) (written int64, err os.Error) {
// Copy copies from src to dst until EOF is reached.
// It returns the number of bytes copied and the error, if any.
-func Copy(src Read, dst Write) (written int64, err os.Error) {
+func Copy(src Reader, dst Writer) (written int64, err os.Error) {
buf := make([]byte, 32*1024);
for {
nr, er := src.Read(buf);
diff --git a/src/lib/io/pipe.go b/src/lib/io/pipe.go
index 446ec69bb4..5f9e7a488c 100644
--- a/src/lib/io/pipe.go
+++ b/src/lib/io/pipe.go
@@ -170,15 +170,15 @@ func (w *pipeWrite) finish() {
}
// Pipe creates a synchronous in-memory pipe.
-// Used to connect code expecting an io.Read
-// with code expecting an io.Write.
+// Used to connect code expecting an io.Reader
+// with code expecting an io.Writer.
//
// Reads on one end are matched by writes on the other.
// Writes don't complete until all the data has been
// written or the read end is closed. Reads return
// any available data or block until the next write
// or the write end is closed.
-func Pipe() (io.ReadClose, io.WriteClose) {
+func Pipe() (io.ReadCloser, io.WriteCloser) {
p := new(pipe);
p.cr = make(chan []byte, 1);
p.cw = make(chan pipeReturn, 1);
diff --git a/src/lib/io/pipe_test.go b/src/lib/io/pipe_test.go
index 3358ef2032..3df6696285 100644
--- a/src/lib/io/pipe_test.go
+++ b/src/lib/io/pipe_test.go
@@ -11,7 +11,7 @@ import (
"time";
)
-func checkWrite(t *testing.T, w io.Write, data []byte, c chan int) {
+func checkWrite(t *testing.T, w Writer, data []byte, c chan int) {
n, err := w.Write(data);
if err != nil {
t.Errorf("write: %v", err);
@@ -25,9 +25,9 @@ func checkWrite(t *testing.T, w io.Write, data []byte, c chan int) {
// Test a single read/write pair.
func TestPipe1(t *testing.T) {
c := make(chan int);
- r, w := io.Pipe();
+ r, w := Pipe();
var buf = make([]byte, 64);
- go checkWrite(t, w, io.StringBytes("hello, world"), c);
+ go checkWrite(t, w, StringBytes("hello, world"), c);
n, err := r.Read(buf);
if err != nil {
t.Errorf("read: %v", err);
@@ -40,7 +40,7 @@ func TestPipe1(t *testing.T) {
w.Close();
}
-func reader(t *testing.T, r io.Read, c chan int) {
+func reader(t *testing.T, r Reader, c chan int) {
var buf = make([]byte, 64);
for {
n, err := r.Read(buf);
@@ -57,7 +57,7 @@ func reader(t *testing.T, r io.Read, c chan int) {
// Test a sequence of read/write pairs.
func TestPipe2(t *testing.T) {
c := make(chan int);
- r, w := io.Pipe();
+ r, w := Pipe();
go reader(t, r, c);
var buf = make([]byte, 64);
for i := 0; i < 5; i++ {
@@ -82,7 +82,7 @@ func TestPipe2(t *testing.T) {
}
// Test a large write that requires multiple reads to satisfy.
-func writer(w io.WriteClose, buf []byte, c chan pipeReturn) {
+func writer(w WriteCloser, buf []byte, c chan pipeReturn) {
n, err := w.Write(buf);
w.Close();
c <- pipeReturn{n, err};
@@ -90,7 +90,7 @@ func writer(w io.WriteClose, buf []byte, c chan pipeReturn) {
func TestPipe3(t *testing.T) {
c := make(chan pipeReturn);
- r, w := io.Pipe();
+ r, w := Pipe();
var wdat = make([]byte, 128);
for i := 0; i < len(wdat); i++ {
wdat[i] = byte(i);
@@ -132,7 +132,7 @@ func TestPipe3(t *testing.T) {
// Test read after/before writer close.
-func delayClose(t *testing.T, cl io.Close, ch chan int) {
+func delayClose(t *testing.T, cl Closer, ch chan int) {
time.Sleep(1000*1000); // 1 ms
if err := cl.Close(); err != nil {
t.Errorf("delayClose: %v", err);
@@ -142,7 +142,7 @@ func delayClose(t *testing.T, cl io.Close, ch chan int) {
func testPipeReadClose(t *testing.T, async bool) {
c := make(chan int, 1);
- r, w := io.Pipe();
+ r, w := Pipe();
if async {
go delayClose(t, w, c);
} else {
@@ -166,13 +166,13 @@ func testPipeReadClose(t *testing.T, async bool) {
func testPipeWriteClose(t *testing.T, async bool) {
c := make(chan int, 1);
- r, w := io.Pipe();
+ r, w := Pipe();
if async {
go delayClose(t, r, c);
} else {
delayClose(t, r, c);
}
- n, err := io.WriteString(w, "hello, world");
+ n, err := WriteString(w, "hello, world");
<-c;
if err != os.EPIPE {
t.Errorf("write on closed pipe: %v", err);