this breaks the dependency of package io on package bytes.
R=rsc
CC=golang-dev
https://golang.org/cl/163085
"exec";
"fmt";
"go/token";
- "io";
+ "io/ioutil";
"os";
)
}();
var xstdout []byte; // TODO(rsc): delete after 6g can take address of out parameter
go func() {
- xstdout, _ = io.ReadAll(r1);
+ xstdout, _ = ioutil.ReadAll(r1);
r1.Close();
c <- true;
}();
- stderr, _ = io.ReadAll(r2);
+ stderr, _ = ioutil.ReadAll(r2);
r2.Close();
<-c;
<-c;
"flag";
"fmt";
"go/scanner";
- "io";
+ "io/ioutil";
"os";
"path";
"strings";
usage()
}
- src, err := io.ReadFile(filename);
+ src, err := ioutil.ReadFile(filename);
if err != nil {
scanner.PrintError(os.Stderr, err)
}
"go/token";
"http";
"io";
+ "io/ioutil";
"log";
"os";
pathutil "path";
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
ndirs := 0;
func readTemplate(name string) *template.Template {
path := pathutil.Join(*tmplroot, name);
- data, err := io.ReadFile(path);
+ data, err := ioutil.ReadFile(path);
if err != nil {
log.Exitf("ReadFile %s: %v", path, err)
}
func serveHTMLDoc(c *http.Conn, r *http.Request, path string) {
// get HTML body contents
- src, err := io.ReadFile(path);
+ src, err := ioutil.ReadFile(path);
if err != nil {
log.Stderrf("%v", err);
http.NotFound(c, r);
func serveTextFile(c *http.Conn, r *http.Request, path string) {
- src, err := io.ReadFile(path);
+ src, err := ioutil.ReadFile(path);
if err != nil {
log.Stderrf("serveTextFile: %s", err)
}
return
}
- list, err := io.ReadDir(path);
+ list, err := ioutil.ReadDir(path);
if err != nil {
http.NotFound(c, r);
return;
"go/parser";
"go/printer";
"go/scanner";
- "io";
+ "io/ioutil";
"os";
pathutil "path";
"strings";
func processFile(f *os.File) os.Error {
- src, err := io.ReadAll(f);
+ src, err := ioutil.ReadAll(f);
if err != nil {
return err
}
fmt.Fprintln(os.Stdout, f.Name())
}
if *write {
- err = io.WriteFile(f.Name(), res.Bytes(), 0);
+ err = ioutil.WriteFile(f.Name(), res.Bytes(), 0);
if err != nil {
return err
}
"flag";
"fmt";
"io";
+ "io/ioutil";
"os";
"patch";
"path";
var err os.Error;
switch len(args) {
case 0:
- data, err = io.ReadAll(os.Stdin)
+ data, err = ioutil.ReadAll(os.Stdin)
case 1:
- data, err = io.ReadFile(args[0])
+ data, err = ioutil.ReadFile(args[0])
default:
usage()
}
}
// Apply changes in memory.
- op, err := pset.Apply(io.ReadFile);
+ op, err := pset.Apply(ioutil.ReadFile);
chk(err);
// Write changes to disk copy: order of commands matters.
changed[o.Dst] = 1;
}
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 {
undoRm(o.Dst)
} else {
image\
image/png\
io\
+ io/ioutil\
json\
log\
malloc\
"bytes";
"fmt";
"io";
+ "io/ioutil";
"testing";
"testing/iotest";
)
func TestWriter(t *testing.T) {
testLoop:
for i, test := range writerTests {
- expected, err := io.ReadFile(test.file);
+ expected, err := ioutil.ReadFile(test.file);
if err != nil {
t.Errorf("test %d: Unexpected error: %v", i, err);
continue;
import (
"bytes";
"fmt";
- "io";
+ "io/ioutil";
"os";
"testing";
)
w.Write(input);
w.Close();
inflater := NewInflater(buffer);
- decompressed, err := io.ReadAll(inflater);
+ decompressed, err := ioutil.ReadAll(inflater);
if err != nil {
t.Errorf("reading inflater: %s", err);
return err;
import (
"io";
+ "io/ioutil";
"os";
"testing";
)
defer zlibr.Close();
// Compare the two.
- b0, err0 := io.ReadAll(golden);
- b1, err1 := io.ReadAll(zlibr);
+ b0, err0 := ioutil.ReadAll(golden);
+ b1, err1 := ioutil.ReadAll(zlibr);
if err0 != nil {
t.Errorf("%s (level=%d): %v", fn, level, err0);
return;
import (
"container/vector";
"fmt";
- "io";
+ "io/ioutil";
"os";
"runtime";
"strconv";
if err != nil {
// There could have been a race, or
// this process could be a zobmie.
- statFile, err2 := io.ReadFile(taskPath + "/" + tidStr + "/stat");
+ statFile, err2 := ioutil.ReadFile(taskPath + "/" + tidStr + "/stat");
if err2 != nil {
switch err2 := err2.(type) {
case *os.PathError:
package ebnf
import (
- "io";
+ "io/ioutil";
"strings";
"testing";
)
func TestFiles(t *testing.T) {
for _, filename := range files {
- src, err := io.ReadFile(filename);
+ src, err := ioutil.ReadFile(filename);
if err != nil {
t.Fatal(err)
}
import (
"bytes";
- "io";
+ "io/ioutil";
"os";
"reflect";
"strings";
func TestDecoder(t *testing.T) {
for _, p := range pairs {
decoder := NewDecoder(bytes.NewBufferString(p.encoded));
- dbuf, err := io.ReadAll(decoder);
+ dbuf, err := ioutil.ReadAll(decoder);
if err != nil {
t.Fatal("Read failed", err)
}
if err != nil {
t.Fatalf("Encoder.Close() = %v want nil", err)
}
- decoded, err := io.ReadAll(NewDecoder(encoded));
+ decoded, err := ioutil.ReadAll(NewDecoder(encoded));
if err != nil {
t.Fatalf("io.ReadAll(NewDecoder(...)): %v", err)
}
import (
"bytes";
- "io";
+ "io/ioutil";
"os";
"reflect";
"strings";
if err != nil {
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 {
- t.Fatalf("io.ReadAll(NewDecoder(...)): %v", err)
+ t.Fatalf("ioutil.ReadAll(NewDecoder(...)): %v", err)
}
if !bytes.Equal(raw, decoded) {
import (
"bytes";
- "io";
+ "io/ioutil";
"os";
"reflect";
"strings";
func TestDecoder(t *testing.T) {
for _, p := range gitPairs {
decoder := NewDecoder(bytes.NewBufferString(p.encoded));
- dbuf, err := io.ReadAll(decoder);
+ dbuf, err := ioutil.ReadAll(decoder);
if err != nil {
t.Fatal("Read failed", err)
}
if err != nil {
t.Fatalf("Encoder.Close() = %v want nil", err)
}
- decoded, err := io.ReadAll(NewDecoder(encoded));
+ decoded, err := ioutil.ReadAll(NewDecoder(encoded));
if err != nil {
- t.Fatalf("io.ReadAll(NewDecoder(...)): %v", err)
+ t.Fatalf("ioutil.ReadAll(NewDecoder(...)): %v", err)
}
if !bytes.Equal(raw, decoded) {
import (
"io";
+ "io/ioutil";
"testing";
)
}
io.WriteString(cmd.Stdin, "hello, world\n");
cmd.Stdin.Close();
- buf, err := io.ReadAll(cmd.Stdout);
+ buf, err := ioutil.ReadAll(cmd.Stdout);
if err != nil {
t.Fatalf("reading from /bin/cat: %v", err)
}
if err != nil {
t.Fatalf("opencmd /bin/echo: %v", err)
}
- buf, err := io.ReadAll(cmd.Stdout);
+ buf, err := ioutil.ReadAll(cmd.Stdout);
if err != nil {
t.Fatalf("reading from /bin/echo: %v", err)
}
flag.Parse();
w := eval.NewWorld();
if *filename != "" {
- data, err := io.ReadFile(*filename);
+ data, err := ioutil.ReadFile(*filename);
if err != nil {
println(err.String());
os.Exit(1);
"go/ast";
"go/scanner";
"io";
+ "io/ioutil";
"os";
pathutil "path";
"strings";
}
}
- return io.ReadFile(filename);
+ return ioutil.ReadFile(filename);
}
// flags that control the amount of source text parsed are ignored.
//
func ParsePkgFile(pkgname, filename string, mode uint) (*ast.File, os.Error) {
- src, err := io.ReadFile(filename);
+ src, err := ioutil.ReadFile(filename);
if err != nil {
return nil, err
}
import (
"bytes";
"flag";
- "io";
+ "io/ioutil";
"go/ast";
"go/parser";
"path";
// update golden files if necessary
if *update {
- if err := io.WriteFile(golden, res, 0644); err != nil {
+ if err := ioutil.WriteFile(golden, res, 0644); err != nil {
t.Error(err)
}
return;
}
// get golden
- gld, err := io.ReadFile(golden);
+ gld, err := ioutil.ReadFile(golden);
if err != nil {
t.Error(err);
return;
package http
import (
- "io";
+ "io/ioutil";
"strings";
"testing";
)
r, _, err := Get("http://www.google.com/robots.txt");
var b []byte;
if err == nil {
- b, err = io.ReadAll(r.Body);
+ b, err = ioutil.ReadAll(r.Body);
r.Body.Close();
}
if err != nil {
"container/vector";
"fmt";
"io";
+ "io/ioutil";
"os";
"strconv";
"strings";
switch strings.Split(ct, ";", 2)[0] {
case "text/plain", "application/x-www-form-urlencoded", "":
var b []byte;
- if b, err = io.ReadAll(r.Body); err != nil {
+ if b, err = ioutil.ReadAll(r.Body); err != nil {
return err
}
query = string(b);
GOFILES=\
io.go\
pipe.go\
- utils.go\
include ../../Make.pkg
// This package provides basic interfaces to I/O primitives.
// Its primary job is to wrap existing implementations of such primitives,
// such as those in package os, into shared public interfaces that
-// abstract the functionality.
-// It also provides buffering primitives and some other basic operations.
+// abstract the functionality, plus some other related primitives.
package io
import (
--- /dev/null
+# 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
// Utility functions.
-package io
+package ioutil
import (
"bytes";
+ "io";
"os";
"sort";
)
// 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;
- _, err := Copy(&buf, r);
+ _, err := io.Copy(&buf, r);
return buf.Bytes(), err;
}
// 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.
buf := bytes.NewBuffer(make([]byte, n)[0:0]);
- _, err = Copy(buf, f);
+ _, err = io.Copy(buf, f);
return buf.Bytes(), err;
}
n, err := f.Write(data);
f.Close();
if err == nil && n < len(data) {
- err = ErrShortWrite
+ err = io.ErrShortWrite
}
return err;
}
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
-package io_test
+package ioutil_test
import (
- . "io";
+ . "io/ioutil";
"os";
"strings";
"testing";
t.Fatalf("ReadFile %s: error expected, none found", filename)
}
- filename = "utils_test.go";
+ filename = "ioutil_test.go";
contents, err = ReadFile(filename);
if err != nil {
t.Fatalf("ReadFile %s: %v", filename, err)
foundObj := false;
for _, dir := range list {
switch {
- case dir.IsRegular() && dir.Name == "utils_test.go":
+ case dir.IsRegular() && dir.Name == "ioutil_test.go":
foundTest = true
case dir.IsDirectory() && dir.Name == "_obj":
foundObj = true
"bytes";
"fmt";
"io";
+ "io/ioutil";
. "os";
"strings";
"testing";
t.Fatalf("WriteAt 7: %d, %v", n, err)
}
- b, err := io.ReadFile("_obj/writetest");
+ b, err := ioutil.ReadFile("_obj/writetest");
if err != nil {
t.Fatalf("ReadFile _obj/writetest: %v", err)
}
package path
import (
- "io";
+ "io/ioutil";
"os";
"strings";
)
return // skip directory entries
}
- list, err := io.ReadDir(path);
+ list, err := ioutil.ReadDir(path);
if err != nil {
if errors != nil {
errors <- err
package time
import (
- "io";
+ "io/ioutil";
"once";
"os";
)
}
func readinfofile(name string) ([]zonetime, bool) {
- buf, err := io.ReadFile(name);
+ buf, err := ioutil.ReadFile(name);
if err != nil {
return nil, false
}
"bufio";
"bytes";
"fmt";
- "io";
+ "io/ioutil";
"os";
"sort";
"strings";
break
}
}
- data, err := io.ReadAll(in);
+ data, err := ioutil.ReadAll(in);
if err != nil {
fmt.Fprintln(os.Stderr, "ReadAll err:", err);
os.Exit(2);
import (
"fmt";
- "io";
+ "io/ioutil";
"os";
"regexp";
"strings";
}
func main() {
- bytes, err := io.ReadFile("/dev/stdin");
+ bytes, err := ioutil.ReadFile("/dev/stdin");
if err != nil {
fmt.Fprintf(os.Stderr, "can't read input: %s\n", err);
os.Exit(2);