Commit 0f62ac42 authored by Russ Cox's avatar Russ Cox

add new function io.ReadAll

R=gri
DELTA=14  (6 added, 4 deleted, 4 changed)
OCL=30072
CL=30074
parent 34038e73
...@@ -11,17 +11,19 @@ import ( ...@@ -11,17 +11,19 @@ import (
"os"; "os";
) )
// ReadAll reads from r until an error or EOF and returns the data it read.
func ReadAll(r Reader) ([]byte, os.Error) {
var buf ByteBuffer;
n, err := io.Copy(r, &buf);
return buf.Data(), err;
}
// ReadFile reads the file named by filename and returns // ReadFile reads the file named by filename and returns the contents.
// its contents if successful.
//
func ReadFile(filename string) ([]byte, os.Error) { func ReadFile(filename string) ([]byte, os.Error) {
f, err := os.Open(filename, os.O_RDONLY, 0); f, err := os.Open(filename, os.O_RDONLY, 0);
if err != nil { if err != nil {
return nil, err; return nil, err;
} }
var b io.ByteBuffer; defer f.Close();
_, err := io.Copy(f, &b); return ReadAll(f);
f.Close();
return b.Data(), err;
} }
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