Commit b0683bd7 authored by Rob Pike's avatar Rob Pike

move ReadFile, WriteFile, and ReadDir into a separate io/ioutil package.

this breaks the dependency of package io on package bytes.

R=rsc
CC=golang-dev
https://golang.org/cl/163085
parent 1eba218e
...@@ -8,7 +8,7 @@ import ( ...@@ -8,7 +8,7 @@ import (
"exec"; "exec";
"fmt"; "fmt";
"go/token"; "go/token";
"io"; "io/ioutil";
"os"; "os";
) )
...@@ -57,11 +57,11 @@ func run(stdin []byte, argv []string) (stdout, stderr []byte, ok bool) { ...@@ -57,11 +57,11 @@ func run(stdin []byte, argv []string) (stdout, stderr []byte, ok bool) {
}(); }();
var xstdout []byte; // TODO(rsc): delete after 6g can take address of out parameter var xstdout []byte; // TODO(rsc): delete after 6g can take address of out parameter
go func() { go func() {
xstdout, _ = io.ReadAll(r1); xstdout, _ = ioutil.ReadAll(r1);
r1.Close(); r1.Close();
c <- true; c <- true;
}(); }();
stderr, _ = io.ReadAll(r2); stderr, _ = ioutil.ReadAll(r2);
r2.Close(); r2.Close();
<-c; <-c;
<-c; <-c;
......
...@@ -10,7 +10,7 @@ import ( ...@@ -10,7 +10,7 @@ import (
"flag"; "flag";
"fmt"; "fmt";
"go/scanner"; "go/scanner";
"io"; "io/ioutil";
"os"; "os";
"path"; "path";
"strings"; "strings";
...@@ -84,7 +84,7 @@ func main() { ...@@ -84,7 +84,7 @@ func main() {
usage() usage()
} }
src, err := io.ReadFile(filename); src, err := ioutil.ReadFile(filename);
if err != nil { if err != nil {
scanner.PrintError(os.Stderr, err) scanner.PrintError(os.Stderr, err)
} }
......
...@@ -15,6 +15,7 @@ import ( ...@@ -15,6 +15,7 @@ import (
"go/token"; "go/token";
"http"; "http";
"io"; "io";
"io/ioutil";
"log"; "log";
"os"; "os";
pathutil "path"; pathutil "path";
...@@ -192,7 +193,7 @@ func newDirTree(path, name string, depth, maxDepth int) *Directory { ...@@ -192,7 +193,7 @@ func newDirTree(path, name string, depth, maxDepth int) *Directory {
return &Directory{depth, path, name, "", nil} return &Directory{depth, path, name, "", nil}
} }
list, _ := io.ReadDir(path); // ignore errors list, _ := ioutil.ReadDir(path); // ignore errors
// determine number of subdirectories and package files // determine number of subdirectories and package files
ndirs := 0; ndirs := 0;
...@@ -633,7 +634,7 @@ var fmap = template.FormatterMap{ ...@@ -633,7 +634,7 @@ var fmap = template.FormatterMap{
func readTemplate(name string) *template.Template { func readTemplate(name string) *template.Template {
path := pathutil.Join(*tmplroot, name); path := pathutil.Join(*tmplroot, name);
data, err := io.ReadFile(path); data, err := ioutil.ReadFile(path);
if err != nil { if err != nil {
log.Exitf("ReadFile %s: %v", path, err) log.Exitf("ReadFile %s: %v", path, err)
} }
...@@ -718,7 +719,7 @@ func commentText(src []byte) (text string) { ...@@ -718,7 +719,7 @@ func commentText(src []byte) (text string) {
func serveHTMLDoc(c *http.Conn, r *http.Request, path string) { func serveHTMLDoc(c *http.Conn, r *http.Request, path string) {
// get HTML body contents // get HTML body contents
src, err := io.ReadFile(path); src, err := ioutil.ReadFile(path);
if err != nil { if err != nil {
log.Stderrf("%v", err); log.Stderrf("%v", err);
http.NotFound(c, r); http.NotFound(c, r);
...@@ -815,7 +816,7 @@ func isTextFile(path string) bool { ...@@ -815,7 +816,7 @@ func isTextFile(path string) bool {
func serveTextFile(c *http.Conn, r *http.Request, path string) { func serveTextFile(c *http.Conn, r *http.Request, path string) {
src, err := io.ReadFile(path); src, err := ioutil.ReadFile(path);
if err != nil { if err != nil {
log.Stderrf("serveTextFile: %s", err) log.Stderrf("serveTextFile: %s", err)
} }
...@@ -834,7 +835,7 @@ func serveDirectory(c *http.Conn, r *http.Request, path string) { ...@@ -834,7 +835,7 @@ func serveDirectory(c *http.Conn, r *http.Request, path string) {
return return
} }
list, err := io.ReadDir(path); list, err := ioutil.ReadDir(path);
if err != nil { if err != nil {
http.NotFound(c, r); http.NotFound(c, r);
return; return;
......
...@@ -12,7 +12,7 @@ import ( ...@@ -12,7 +12,7 @@ import (
"go/parser"; "go/parser";
"go/printer"; "go/printer";
"go/scanner"; "go/scanner";
"io"; "io/ioutil";
"os"; "os";
pathutil "path"; pathutil "path";
"strings"; "strings";
...@@ -86,7 +86,7 @@ func isGoFile(d *os.Dir) bool { ...@@ -86,7 +86,7 @@ func isGoFile(d *os.Dir) bool {
func processFile(f *os.File) os.Error { func processFile(f *os.File) os.Error {
src, err := io.ReadAll(f); src, err := ioutil.ReadAll(f);
if err != nil { if err != nil {
return err return err
} }
...@@ -112,7 +112,7 @@ func processFile(f *os.File) os.Error { ...@@ -112,7 +112,7 @@ func processFile(f *os.File) os.Error {
fmt.Fprintln(os.Stdout, f.Name()) fmt.Fprintln(os.Stdout, f.Name())
} }
if *write { if *write {
err = io.WriteFile(f.Name(), res.Bytes(), 0); err = ioutil.WriteFile(f.Name(), res.Bytes(), 0);
if err != nil { if err != nil {
return err return err
} }
......
...@@ -11,6 +11,7 @@ import ( ...@@ -11,6 +11,7 @@ import (
"flag"; "flag";
"fmt"; "fmt";
"io"; "io";
"io/ioutil";
"os"; "os";
"patch"; "patch";
"path"; "path";
...@@ -35,9 +36,9 @@ func main() { ...@@ -35,9 +36,9 @@ func main() {
var err os.Error; var err os.Error;
switch len(args) { switch len(args) {
case 0: case 0:
data, err = io.ReadAll(os.Stdin) data, err = ioutil.ReadAll(os.Stdin)
case 1: case 1:
data, err = io.ReadFile(args[0]) data, err = ioutil.ReadFile(args[0])
default: default:
usage() usage()
} }
...@@ -87,7 +88,7 @@ func main() { ...@@ -87,7 +88,7 @@ func main() {
} }
// Apply changes in memory. // Apply changes in memory.
op, err := pset.Apply(io.ReadFile); op, err := pset.Apply(ioutil.ReadFile);
chk(err); chk(err);
// Write changes to disk copy: order of commands matters. // Write changes to disk copy: order of commands matters.
...@@ -143,7 +144,7 @@ func main() { ...@@ -143,7 +144,7 @@ func main() {
changed[o.Dst] = 1; changed[o.Dst] = 1;
} }
if o.Data != nil { if o.Data != nil {
chk(io.WriteFile(o.Dst, o.Data, 0644)); chk(ioutil.WriteFile(o.Dst, o.Data, 0644));
if o.Verb == patch.Add { if o.Verb == patch.Add {
undoRm(o.Dst) undoRm(o.Dst)
} else { } else {
......
...@@ -70,6 +70,7 @@ DIRS=\ ...@@ -70,6 +70,7 @@ DIRS=\
image\ image\
image/png\ image/png\
io\ io\
io/ioutil\
json\ json\
log\ log\
malloc\ malloc\
......
...@@ -8,6 +8,7 @@ import ( ...@@ -8,6 +8,7 @@ import (
"bytes"; "bytes";
"fmt"; "fmt";
"io"; "io";
"io/ioutil";
"testing"; "testing";
"testing/iotest"; "testing/iotest";
) )
...@@ -121,7 +122,7 @@ func bytediff(a []byte, b []byte) string { ...@@ -121,7 +122,7 @@ func bytediff(a []byte, b []byte) string {
func TestWriter(t *testing.T) { func TestWriter(t *testing.T) {
testLoop: testLoop:
for i, test := range writerTests { for i, test := range writerTests {
expected, err := io.ReadFile(test.file); expected, err := ioutil.ReadFile(test.file);
if err != nil { if err != nil {
t.Errorf("test %d: Unexpected error: %v", i, err); t.Errorf("test %d: Unexpected error: %v", i, err);
continue; continue;
......
...@@ -7,7 +7,7 @@ package flate ...@@ -7,7 +7,7 @@ package flate
import ( import (
"bytes"; "bytes";
"fmt"; "fmt";
"io"; "io/ioutil";
"os"; "os";
"testing"; "testing";
) )
...@@ -96,7 +96,7 @@ func testToFromWithLevel(t *testing.T, level int, input []byte, name string) os. ...@@ -96,7 +96,7 @@ func testToFromWithLevel(t *testing.T, level int, input []byte, name string) os.
w.Write(input); w.Write(input);
w.Close(); w.Close();
inflater := NewInflater(buffer); inflater := NewInflater(buffer);
decompressed, err := io.ReadAll(inflater); decompressed, err := ioutil.ReadAll(inflater);
if err != nil { if err != nil {
t.Errorf("reading inflater: %s", err); t.Errorf("reading inflater: %s", err);
return err; return err;
......
...@@ -6,6 +6,7 @@ package zlib ...@@ -6,6 +6,7 @@ package zlib
import ( import (
"io"; "io";
"io/ioutil";
"os"; "os";
"testing"; "testing";
) )
...@@ -72,8 +73,8 @@ func testFileLevel(t *testing.T, fn string, level int) { ...@@ -72,8 +73,8 @@ func testFileLevel(t *testing.T, fn string, level int) {
defer zlibr.Close(); defer zlibr.Close();
// Compare the two. // Compare the two.
b0, err0 := io.ReadAll(golden); b0, err0 := ioutil.ReadAll(golden);
b1, err1 := io.ReadAll(zlibr); b1, err1 := ioutil.ReadAll(zlibr);
if err0 != nil { if err0 != nil {
t.Errorf("%s (level=%d): %v", fn, level, err0); t.Errorf("%s (level=%d): %v", fn, level, err0);
return; return;
......
...@@ -9,7 +9,7 @@ package proc ...@@ -9,7 +9,7 @@ package proc
import ( import (
"container/vector"; "container/vector";
"fmt"; "fmt";
"io"; "io/ioutil";
"os"; "os";
"runtime"; "runtime";
"strconv"; "strconv";
...@@ -1215,7 +1215,7 @@ func (p *process) attachAllThreads() os.Error { ...@@ -1215,7 +1215,7 @@ func (p *process) attachAllThreads() os.Error {
if err != nil { if err != nil {
// There could have been a race, or // There could have been a race, or
// this process could be a zobmie. // this process could be a zobmie.
statFile, err2 := io.ReadFile(taskPath + "/" + tidStr + "/stat"); statFile, err2 := ioutil.ReadFile(taskPath + "/" + tidStr + "/stat");
if err2 != nil { if err2 != nil {
switch err2 := err2.(type) { switch err2 := err2.(type) {
case *os.PathError: case *os.PathError:
......
...@@ -5,7 +5,7 @@ ...@@ -5,7 +5,7 @@
package ebnf package ebnf
import ( import (
"io"; "io/ioutil";
"strings"; "strings";
"testing"; "testing";
) )
...@@ -65,7 +65,7 @@ var files = []string{ ...@@ -65,7 +65,7 @@ var files = []string{
func TestFiles(t *testing.T) { func TestFiles(t *testing.T) {
for _, filename := range files { for _, filename := range files {
src, err := io.ReadFile(filename); src, err := ioutil.ReadFile(filename);
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }
......
...@@ -6,7 +6,7 @@ package ascii85 ...@@ -6,7 +6,7 @@ package ascii85
import ( import (
"bytes"; "bytes";
"io"; "io/ioutil";
"os"; "os";
"reflect"; "reflect";
"strings"; "strings";
...@@ -111,7 +111,7 @@ func TestDecode(t *testing.T) { ...@@ -111,7 +111,7 @@ func TestDecode(t *testing.T) {
func TestDecoder(t *testing.T) { func TestDecoder(t *testing.T) {
for _, p := range pairs { for _, p := range pairs {
decoder := NewDecoder(bytes.NewBufferString(p.encoded)); decoder := NewDecoder(bytes.NewBufferString(p.encoded));
dbuf, err := io.ReadAll(decoder); dbuf, err := ioutil.ReadAll(decoder);
if err != nil { if err != nil {
t.Fatal("Read failed", err) t.Fatal("Read failed", err)
} }
...@@ -176,7 +176,7 @@ func TestBig(t *testing.T) { ...@@ -176,7 +176,7 @@ func TestBig(t *testing.T) {
if err != nil { if err != nil {
t.Fatalf("Encoder.Close() = %v want nil", err) t.Fatalf("Encoder.Close() = %v want nil", err)
} }
decoded, err := io.ReadAll(NewDecoder(encoded)); decoded, err := ioutil.ReadAll(NewDecoder(encoded));
if err != nil { if err != nil {
t.Fatalf("io.ReadAll(NewDecoder(...)): %v", err) t.Fatalf("io.ReadAll(NewDecoder(...)): %v", err)
} }
......
...@@ -6,7 +6,7 @@ package base64 ...@@ -6,7 +6,7 @@ package base64
import ( import (
"bytes"; "bytes";
"io"; "io/ioutil";
"os"; "os";
"reflect"; "reflect";
"strings"; "strings";
...@@ -184,9 +184,9 @@ func TestBig(t *testing.T) { ...@@ -184,9 +184,9 @@ func TestBig(t *testing.T) {
if err != nil { if err != nil {
t.Fatalf("Encoder.Close() = %v want nil", err) t.Fatalf("Encoder.Close() = %v want nil", err)
} }
decoded, err := io.ReadAll(NewDecoder(StdEncoding, encoded)); decoded, err := ioutil.ReadAll(NewDecoder(StdEncoding, encoded));
if err != nil { if err != nil {
t.Fatalf("io.ReadAll(NewDecoder(...)): %v", err) t.Fatalf("ioutil.ReadAll(NewDecoder(...)): %v", err)
} }
if !bytes.Equal(raw, decoded) { if !bytes.Equal(raw, decoded) {
......
...@@ -6,7 +6,7 @@ package git85 ...@@ -6,7 +6,7 @@ package git85
import ( import (
"bytes"; "bytes";
"io"; "io/ioutil";
"os"; "os";
"reflect"; "reflect";
"strings"; "strings";
...@@ -117,7 +117,7 @@ func TestDecode(t *testing.T) { ...@@ -117,7 +117,7 @@ func TestDecode(t *testing.T) {
func TestDecoder(t *testing.T) { func TestDecoder(t *testing.T) {
for _, p := range gitPairs { for _, p := range gitPairs {
decoder := NewDecoder(bytes.NewBufferString(p.encoded)); decoder := NewDecoder(bytes.NewBufferString(p.encoded));
dbuf, err := io.ReadAll(decoder); dbuf, err := ioutil.ReadAll(decoder);
if err != nil { if err != nil {
t.Fatal("Read failed", err) t.Fatal("Read failed", err)
} }
...@@ -182,9 +182,9 @@ func TestGitBig(t *testing.T) { ...@@ -182,9 +182,9 @@ func TestGitBig(t *testing.T) {
if err != nil { if err != nil {
t.Fatalf("Encoder.Close() = %v want nil", err) t.Fatalf("Encoder.Close() = %v want nil", err)
} }
decoded, err := io.ReadAll(NewDecoder(encoded)); decoded, err := ioutil.ReadAll(NewDecoder(encoded));
if err != nil { if err != nil {
t.Fatalf("io.ReadAll(NewDecoder(...)): %v", err) t.Fatalf("ioutil.ReadAll(NewDecoder(...)): %v", err)
} }
if !bytes.Equal(raw, decoded) { if !bytes.Equal(raw, decoded) {
......
...@@ -6,6 +6,7 @@ package exec ...@@ -6,6 +6,7 @@ package exec
import ( import (
"io"; "io";
"io/ioutil";
"testing"; "testing";
) )
...@@ -17,7 +18,7 @@ func TestRunCat(t *testing.T) { ...@@ -17,7 +18,7 @@ func TestRunCat(t *testing.T) {
} }
io.WriteString(cmd.Stdin, "hello, world\n"); io.WriteString(cmd.Stdin, "hello, world\n");
cmd.Stdin.Close(); cmd.Stdin.Close();
buf, err := io.ReadAll(cmd.Stdout); buf, err := ioutil.ReadAll(cmd.Stdout);
if err != nil { if err != nil {
t.Fatalf("reading from /bin/cat: %v", err) t.Fatalf("reading from /bin/cat: %v", err)
} }
...@@ -35,7 +36,7 @@ func TestRunEcho(t *testing.T) { ...@@ -35,7 +36,7 @@ func TestRunEcho(t *testing.T) {
if err != nil { if err != nil {
t.Fatalf("opencmd /bin/echo: %v", err) t.Fatalf("opencmd /bin/echo: %v", err)
} }
buf, err := io.ReadAll(cmd.Stdout); buf, err := ioutil.ReadAll(cmd.Stdout);
if err != nil { if err != nil {
t.Fatalf("reading from /bin/echo: %v", err) t.Fatalf("reading from /bin/echo: %v", err)
} }
......
...@@ -20,7 +20,7 @@ func main() { ...@@ -20,7 +20,7 @@ func main() {
flag.Parse(); flag.Parse();
w := eval.NewWorld(); w := eval.NewWorld();
if *filename != "" { if *filename != "" {
data, err := io.ReadFile(*filename); data, err := ioutil.ReadFile(*filename);
if err != nil { if err != nil {
println(err.String()); println(err.String());
os.Exit(1); os.Exit(1);
......
...@@ -12,6 +12,7 @@ import ( ...@@ -12,6 +12,7 @@ import (
"go/ast"; "go/ast";
"go/scanner"; "go/scanner";
"io"; "io";
"io/ioutil";
"os"; "os";
pathutil "path"; pathutil "path";
"strings"; "strings";
...@@ -46,7 +47,7 @@ func readSource(filename string, src interface{}) ([]byte, os.Error) { ...@@ -46,7 +47,7 @@ func readSource(filename string, src interface{}) ([]byte, os.Error) {
} }
} }
return io.ReadFile(filename); return ioutil.ReadFile(filename);
} }
...@@ -138,7 +139,7 @@ func ParseFile(filename string, src interface{}, mode uint) (*ast.File, os.Error ...@@ -138,7 +139,7 @@ func ParseFile(filename string, src interface{}, mode uint) (*ast.File, os.Error
// flags that control the amount of source text parsed are ignored. // flags that control the amount of source text parsed are ignored.
// //
func ParsePkgFile(pkgname, filename string, mode uint) (*ast.File, os.Error) { func ParsePkgFile(pkgname, filename string, mode uint) (*ast.File, os.Error) {
src, err := io.ReadFile(filename); src, err := ioutil.ReadFile(filename);
if err != nil { if err != nil {
return nil, err return nil, err
} }
......
...@@ -7,7 +7,7 @@ package printer ...@@ -7,7 +7,7 @@ package printer
import ( import (
"bytes"; "bytes";
"flag"; "flag";
"io"; "io/ioutil";
"go/ast"; "go/ast";
"go/parser"; "go/parser";
"path"; "path";
...@@ -70,14 +70,14 @@ func check(t *testing.T, source, golden string, mode checkMode) { ...@@ -70,14 +70,14 @@ func check(t *testing.T, source, golden string, mode checkMode) {
// update golden files if necessary // update golden files if necessary
if *update { if *update {
if err := io.WriteFile(golden, res, 0644); err != nil { if err := ioutil.WriteFile(golden, res, 0644); err != nil {
t.Error(err) t.Error(err)
} }
return; return;
} }
// get golden // get golden
gld, err := io.ReadFile(golden); gld, err := ioutil.ReadFile(golden);
if err != nil { if err != nil {
t.Error(err); t.Error(err);
return; return;
......
...@@ -7,7 +7,7 @@ ...@@ -7,7 +7,7 @@
package http package http
import ( import (
"io"; "io/ioutil";
"strings"; "strings";
"testing"; "testing";
) )
...@@ -19,7 +19,7 @@ func TestClient(t *testing.T) { ...@@ -19,7 +19,7 @@ func TestClient(t *testing.T) {
r, _, err := Get("http://www.google.com/robots.txt"); r, _, err := Get("http://www.google.com/robots.txt");
var b []byte; var b []byte;
if err == nil { if err == nil {
b, err = io.ReadAll(r.Body); b, err = ioutil.ReadAll(r.Body);
r.Body.Close(); r.Body.Close();
} }
if err != nil { if err != nil {
......
...@@ -15,6 +15,7 @@ import ( ...@@ -15,6 +15,7 @@ import (
"container/vector"; "container/vector";
"fmt"; "fmt";
"io"; "io";
"io/ioutil";
"os"; "os";
"strconv"; "strconv";
"strings"; "strings";
...@@ -626,7 +627,7 @@ func (r *Request) ParseForm() (err os.Error) { ...@@ -626,7 +627,7 @@ func (r *Request) ParseForm() (err os.Error) {
switch strings.Split(ct, ";", 2)[0] { switch strings.Split(ct, ";", 2)[0] {
case "text/plain", "application/x-www-form-urlencoded", "": case "text/plain", "application/x-www-form-urlencoded", "":
var b []byte; var b []byte;
if b, err = io.ReadAll(r.Body); err != nil { if b, err = ioutil.ReadAll(r.Body); err != nil {
return err return err
} }
query = string(b); query = string(b);
......
...@@ -8,6 +8,5 @@ TARG=io ...@@ -8,6 +8,5 @@ TARG=io
GOFILES=\ GOFILES=\
io.go\ io.go\
pipe.go\ pipe.go\
utils.go\
include ../../Make.pkg include ../../Make.pkg
...@@ -5,8 +5,7 @@ ...@@ -5,8 +5,7 @@
// This package provides basic interfaces to I/O primitives. // This package provides basic interfaces to I/O primitives.
// Its primary job is to wrap existing implementations of such primitives, // Its primary job is to wrap existing implementations of such primitives,
// such as those in package os, into shared public interfaces that // such as those in package os, into shared public interfaces that
// abstract the functionality. // abstract the functionality, plus some other related primitives.
// It also provides buffering primitives and some other basic operations.
package io package io
import ( import (
......
# Copyright 2009 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.
include ../../../Make.$(GOARCH)
TARG=io/ioutil
GOFILES=\
ioutil.go\
include ../../../Make.pkg
...@@ -4,18 +4,19 @@ ...@@ -4,18 +4,19 @@
// Utility functions. // Utility functions.
package io package ioutil
import ( import (
"bytes"; "bytes";
"io";
"os"; "os";
"sort"; "sort";
) )
// ReadAll reads from r until an error or EOF and returns the data it read. // ReadAll reads from r until an error or EOF and returns the data it read.
func ReadAll(r Reader) ([]byte, os.Error) { func ReadAll(r io.Reader) ([]byte, os.Error) {
var buf bytes.Buffer; var buf bytes.Buffer;
_, err := Copy(&buf, r); _, err := io.Copy(&buf, r);
return buf.Bytes(), err; return buf.Bytes(), err;
} }
...@@ -41,7 +42,7 @@ func ReadFile(filename string) ([]byte, os.Error) { ...@@ -41,7 +42,7 @@ func ReadFile(filename string) ([]byte, os.Error) {
// we'll either waste some space off the end or reallocate as needed, but // we'll either waste some space off the end or reallocate as needed, but
// in the overwhelmingly common case we'll get it just right. // in the overwhelmingly common case we'll get it just right.
buf := bytes.NewBuffer(make([]byte, n)[0:0]); buf := bytes.NewBuffer(make([]byte, n)[0:0]);
_, err = Copy(buf, f); _, err = io.Copy(buf, f);
return buf.Bytes(), err; return buf.Bytes(), err;
} }
...@@ -56,7 +57,7 @@ func WriteFile(filename string, data []byte, perm int) os.Error { ...@@ -56,7 +57,7 @@ func WriteFile(filename string, data []byte, perm int) os.Error {
n, err := f.Write(data); n, err := f.Write(data);
f.Close(); f.Close();
if err == nil && n < len(data) { if err == nil && n < len(data) {
err = ErrShortWrite err = io.ErrShortWrite
} }
return err; return err;
} }
......
...@@ -2,10 +2,10 @@ ...@@ -2,10 +2,10 @@
// Use of this source code is governed by a BSD-style // Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file. // license that can be found in the LICENSE file.
package io_test package ioutil_test
import ( import (
. "io"; . "io/ioutil";
"os"; "os";
"strings"; "strings";
"testing"; "testing";
...@@ -28,7 +28,7 @@ func TestReadFile(t *testing.T) { ...@@ -28,7 +28,7 @@ func TestReadFile(t *testing.T) {
t.Fatalf("ReadFile %s: error expected, none found", filename) t.Fatalf("ReadFile %s: error expected, none found", filename)
} }
filename = "utils_test.go"; filename = "ioutil_test.go";
contents, err = ReadFile(filename); contents, err = ReadFile(filename);
if err != nil { if err != nil {
t.Fatalf("ReadFile %s: %v", filename, err) t.Fatalf("ReadFile %s: %v", filename, err)
...@@ -78,7 +78,7 @@ func TestReadDir(t *testing.T) { ...@@ -78,7 +78,7 @@ func TestReadDir(t *testing.T) {
foundObj := false; foundObj := false;
for _, dir := range list { for _, dir := range list {
switch { switch {
case dir.IsRegular() && dir.Name == "utils_test.go": case dir.IsRegular() && dir.Name == "ioutil_test.go":
foundTest = true foundTest = true
case dir.IsDirectory() && dir.Name == "_obj": case dir.IsDirectory() && dir.Name == "_obj":
foundObj = true foundObj = true
......
...@@ -8,6 +8,7 @@ import ( ...@@ -8,6 +8,7 @@ import (
"bytes"; "bytes";
"fmt"; "fmt";
"io"; "io";
"io/ioutil";
. "os"; . "os";
"strings"; "strings";
"testing"; "testing";
...@@ -666,7 +667,7 @@ func TestWriteAt(t *testing.T) { ...@@ -666,7 +667,7 @@ func TestWriteAt(t *testing.T) {
t.Fatalf("WriteAt 7: %d, %v", n, err) t.Fatalf("WriteAt 7: %d, %v", n, err)
} }
b, err := io.ReadFile("_obj/writetest"); b, err := ioutil.ReadFile("_obj/writetest");
if err != nil { if err != nil {
t.Fatalf("ReadFile _obj/writetest: %v", err) t.Fatalf("ReadFile _obj/writetest: %v", err)
} }
......
...@@ -7,7 +7,7 @@ ...@@ -7,7 +7,7 @@
package path package path
import ( import (
"io"; "io/ioutil";
"os"; "os";
"strings"; "strings";
) )
...@@ -155,7 +155,7 @@ func walk(path string, d *os.Dir, v Visitor, errors chan<- os.Error) { ...@@ -155,7 +155,7 @@ func walk(path string, d *os.Dir, v Visitor, errors chan<- os.Error) {
return // skip directory entries return // skip directory entries
} }
list, err := io.ReadDir(path); list, err := ioutil.ReadDir(path);
if err != nil { if err != nil {
if errors != nil { if errors != nil {
errors <- err errors <- err
......
...@@ -10,7 +10,7 @@ ...@@ -10,7 +10,7 @@
package time package time
import ( import (
"io"; "io/ioutil";
"once"; "once";
"os"; "os";
) )
...@@ -195,7 +195,7 @@ func parseinfo(bytes []byte) (zt []zonetime, ok bool) { ...@@ -195,7 +195,7 @@ func parseinfo(bytes []byte) (zt []zonetime, ok bool) {
} }
func readinfofile(name string) ([]zonetime, bool) { func readinfofile(name string) ([]zonetime, bool) {
buf, err := io.ReadFile(name); buf, err := ioutil.ReadFile(name);
if err != nil { if err != nil {
return nil, false return nil, false
} }
......
...@@ -39,7 +39,7 @@ import ( ...@@ -39,7 +39,7 @@ import (
"bufio"; "bufio";
"bytes"; "bytes";
"fmt"; "fmt";
"io"; "io/ioutil";
"os"; "os";
"sort"; "sort";
"strings"; "strings";
...@@ -122,7 +122,7 @@ func main() { ...@@ -122,7 +122,7 @@ func main() {
break break
} }
} }
data, err := io.ReadAll(in); data, err := ioutil.ReadAll(in);
if err != nil { if err != nil {
fmt.Fprintln(os.Stderr, "ReadAll err:", err); fmt.Fprintln(os.Stderr, "ReadAll err:", err);
os.Exit(2); os.Exit(2);
......
...@@ -37,7 +37,7 @@ package main ...@@ -37,7 +37,7 @@ package main
import ( import (
"fmt"; "fmt";
"io"; "io/ioutil";
"os"; "os";
"regexp"; "regexp";
"strings"; "strings";
...@@ -88,7 +88,7 @@ func countMatches(pat string, bytes []byte) int { ...@@ -88,7 +88,7 @@ func countMatches(pat string, bytes []byte) int {
} }
func main() { func main() {
bytes, err := io.ReadFile("/dev/stdin"); bytes, err := ioutil.ReadFile("/dev/stdin");
if err != nil { if err != nil {
fmt.Fprintf(os.Stderr, "can't read input: %s\n", err); fmt.Fprintf(os.Stderr, "can't read input: %s\n", err);
os.Exit(2); os.Exit(2);
......
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