}
var buf bytes.Buffer;
- io.Copy(r, &buf);
+ io.Copy(&buf, r);
wait, err := os.Wait(pid, 0);
if err != nil {
os.Stderr.Write(buf.Bytes());
// // end of tar archive
// break
// }
-// io.Copy(tr, data);
+// io.Copy(data, tr);
// }
type Reader struct {
r io.Reader;
if sr, ok := tr.r.(io.Seeker); ok {
_, tr.err = sr.Seek(nr, 1);
} else {
- _, tr.err = io.Copyn(tr.r, ignoreWriter{}, nr);
+ _, tr.err = io.Copyn(ignoreWriter{}, tr.r, nr);
}
tr.nb, tr.pad = 0, 0;
}
// if err := tw.WriteHeader(hdr); err != nil {
// // handle error
// }
-// io.Copy(data, tw);
+// io.Copy(tw, data);
// tw.Close();
type Writer struct {
w io.Writer;
t.Errorf("%s: got name %s", tt.name, gzip.Name);
}
b.Reset();
- n, err := io.Copy(gzip, b);
+ n, err := io.Copy(b, gzip);
if err != tt.err {
t.Errorf("%s: io.Copy: %v want %v", tt.name, err, tt.err);
}
}
defer zlib.Close();
b.Reset();
- n, err := io.Copy(zlib, b);
+ n, err := io.Copy(b, zlib);
if err != nil {
if err != tt.err {
t.Errorf("%s: io.Copy: %v want %v", tt.desc, err, tt.err);
var crypt bytes.Buffer;
w := NewCBCEncrypter(c, tt.iv, &crypt);
var r io.Reader = bytes.NewBuffer(tt.in);
- n, err := io.Copy(r, w);
+ n, err := io.Copy(w, r);
if n != int64(len(tt.in)) || err != nil {
t.Errorf("%s: CBCEncrypter io.Copy = %d, %v want %d, nil", test, n, err, len(tt.in));
} else if d := crypt.Bytes(); !same(tt.out, d) {
var plain bytes.Buffer;
r = NewCBCDecrypter(c, tt.iv, bytes.NewBuffer(tt.out));
w = &plain;
- n, err = io.Copy(r, w);
+ n, err = io.Copy(w, r);
if n != int64(len(tt.out)) || err != nil {
t.Errorf("%s: CBCDecrypter io.Copy = %d, %v want %d, nil", test, n, err, len(tt.out));
} else if d := plain.Bytes(); !same(tt.in, d) {
var crypt bytes.Buffer;
w := NewCFBEncrypter(c, tt.s, tt.iv, &crypt);
var r io.Reader = bytes.NewBuffer(tt.in);
- n, err := io.Copy(r, w);
+ n, err := io.Copy(w, r);
if n != int64(len(tt.in)) || err != nil {
t.Errorf("%s: CFBEncrypter io.Copy = %d, %v want %d, nil", test, n, err, len(tt.in));
} else if d := crypt.Bytes(); !same(tt.out, d) {
var plain bytes.Buffer;
r = NewCFBDecrypter(c, tt.s, tt.iv, bytes.NewBuffer(tt.out));
w = &plain;
- n, err = io.Copy(r, w);
+ n, err = io.Copy(w, r);
if n != int64(len(tt.out)) || err != nil {
t.Errorf("%s: CFBDecrypter io.Copy = %d, %v want %d, nil", test, n, err, len(tt.out));
} else if d := plain.Bytes(); !same(tt.in, d) {
in := tt.in[0 : len(tt.in)-j];
w := NewCTRWriter(c, tt.iv, &crypt);
var r io.Reader = bytes.NewBuffer(in);
- n, err := io.Copy(r, w);
+ n, err := io.Copy(w, r);
if n != int64(len(in)) || err != nil {
t.Errorf("%s/%d: CTRWriter io.Copy = %d, %v want %d, nil", test, len(in), n, err, len(in));
} else if d, out := crypt.Bytes(), tt.out[0:len(in)]; !same(out, d) {
out := tt.out[0 : len(tt.out)-j];
r := NewCTRReader(c, tt.iv, bytes.NewBuffer(out));
w := &plain;
- n, err := io.Copy(r, w);
+ n, err := io.Copy(w, r);
if n != int64(len(out)) || err != nil {
t.Errorf("%s/%d: CTRReader io.Copy = %d, %v want %d, nil", test, len(out), n, err, len(out));
} else if d, in := plain.Bytes(), tt.in[0:len(out)]; !same(in, d) {
}
b.Reset();
enc := NewEAXEncrypter(c, tt.nonce, tt.header, 16, b);
- n, err := io.Copy(bytes.NewBuffer(tt.msg), enc);
+ n, err := io.Copy(enc, bytes.NewBuffer(tt.msg));
if n != int64(len(tt.msg)) || err != nil {
t.Fatalf("%s: io.Copy into encrypter: %d, %s", test, n, err);
}
}
b.Reset();
dec := NewEAXDecrypter(c, tt.nonce, tt.header, 16, bytes.NewBuffer(tt.cipher));
- n, err := io.Copy(dec, b);
+ n, err := io.Copy(b, dec);
if n != int64(len(tt.msg)) || err != nil {
t.Fatalf("%s: io.Copy into decrypter: %d, %s", test, n, err);
}
var crypt bytes.Buffer;
w := NewECBEncrypter(c, &crypt);
var r io.Reader = bytes.NewBuffer(tt.in);
- n, err := io.Copy(r, w);
+ n, err := io.Copy(w, r);
if n != int64(len(tt.in)) || err != nil {
t.Errorf("%s: ECBReader io.Copy = %d, %v want %d, nil", test, n, err, len(tt.in));
} else if d := crypt.Bytes(); !same(tt.out, d) {
var plain bytes.Buffer;
r = NewECBDecrypter(c, bytes.NewBuffer(tt.out));
w = &plain;
- n, err = io.Copy(r, w);
+ n, err = io.Copy(w, r);
if n != int64(len(tt.out)) || err != nil {
t.Errorf("%s: ECBWriter io.Copy = %d, %v want %d, nil", test, n, err, len(tt.out));
} else if d := plain.Bytes(); !same(tt.in, d) {
// copy plain into w in increasingly large chunks: 1, 1, 2, 4, 8, ...
// if frag != 0, move the 1 to the end to cause fragmentation.
if frag == 0 {
- _, err := io.Copyn(r, w, 1);
+ _, err := io.Copyn(w, r, 1);
if err != nil {
t.Errorf("block=%d frag=0: first Copyn: %s", block, err);
continue;
}
}
for n := 1; n <= len(plain)/2; n *= 2 {
- _, err := io.Copyn(r, w, int64(n));
+ _, err := io.Copyn(w, r, int64(n));
if err != nil {
t.Errorf("block=%d frag=%d: Copyn %d: %s", block, frag, n, err);
}
}
if frag != 0 {
- _, err := io.Copyn(r, w, 1);
+ _, err := io.Copyn(w, r, 1);
if err != nil {
t.Errorf("block=%d frag=1: last Copyn: %s", block, err);
continue;
// read from crypt in increasingly large chunks: 1, 1, 2, 4, 8, ...
// if frag == 1, move the 1 to the end to cause fragmentation.
if frag == 0 {
- _, err := io.Copyn(r, b, 1);
+ _, err := io.Copyn(b, r, 1);
if err != nil {
t.Errorf("%s: first Copyn: %s", test, err);
continue;
}
}
for n := 1; n <= maxio/2; n *= 2 {
- _, err := io.Copyn(r, b, int64(n));
+ _, err := io.Copyn(b, r, int64(n));
if err != nil {
t.Errorf("%s: Copyn %d: %s", test, n, err);
}
}
if frag != 0 {
- _, err := io.Copyn(r, b, 1);
+ _, err := io.Copyn(b, r, 1);
if err != nil {
t.Errorf("%s: last Copyn: %s", test, err);
continue;
in := tt.in[0 : len(tt.in)-j];
w := NewOFBWriter(c, tt.iv, &crypt);
var r io.Reader = bytes.NewBuffer(in);
- n, err := io.Copy(r, w);
+ n, err := io.Copy(w, r);
if n != int64(len(in)) || err != nil {
t.Errorf("%s/%d: OFBWriter io.Copy = %d, %v want %d, nil", test, len(in), n, err, len(in));
} else if d, out := crypt.Bytes(), tt.out[0:len(in)]; !same(out, d) {
out := tt.out[0 : len(tt.out)-j];
r := NewOFBReader(c, tt.iv, bytes.NewBuffer(out));
w := &plain;
- n, err := io.Copy(r, w);
+ n, err := io.Copy(w, r);
if n != int64(len(out)) || err != nil {
t.Errorf("%s/%d: OFBReader io.Copy = %d, %v want %d, nil", test, len(out), n, err, len(out));
} else if d, in := plain.Bytes(), tt.in[0:len(out)]; !same(in, d) {
// copy plain into w in increasingly large chunks: 1, 1, 2, 4, 8, ...
// if frag != 0, move the 1 to the end to cause fragmentation.
if frag == 0 {
- _, err := io.Copyn(r, w, 1);
+ _, err := io.Copyn(w, r, 1);
if err != nil {
t.Errorf("%s: first Copyn: %s", test, err);
continue;
}
}
for n := 1; n <= len(plain)/2; n *= 2 {
- _, err := io.Copyn(r, w, int64(n));
+ _, err := io.Copyn(w, r, int64(n));
if err != nil {
t.Errorf("%s: Copyn %d: %s", test, n, err);
}
// read from crypt in increasingly large chunks: 1, 1, 2, 4, 8, ...
// if frag == 1, move the 1 to the end to cause fragmentation.
if frag == 0 {
- _, err := io.Copyn(r, b, 1);
+ _, err := io.Copyn(b, r, 1);
if err != nil {
t.Errorf("%s: first Copyn: %s", test, err);
continue;
}
}
for n := 1; n <= maxio/2; n *= 2 {
- _, err := io.Copyn(r, b, int64(n));
+ _, err := io.Copyn(b, r, int64(n));
if err != nil {
t.Errorf("%s: Copyn %d: %s", test, n, err);
}
}
case io.Reader:
var buf bytes.Buffer;
- _, err := io.Copy(s, &buf);
+ _, err := io.Copy(&buf, s);
if err != nil {
return nil, err;
}
}
c.Write(b);
}
- io.Copy(f, c);
+ io.Copy(c, f);
}
// ServeFile replies to the request with the contents of the named file or directory.
ctr.n++;
case "POST":
buf := new(bytes.Buffer);
- io.Copy(req.Body, buf);
+ io.Copy(buf, req.Body);
body := buf.String();
if n, err := strconv.Atoi(body); err != nil {
fmt.Fprintf(c, "bad POST: %v\nbody: [%v]\n", err, body);
fmt.Fprintf(c, "open %s: %v\n", path, err);
return;
}
- n, err1 := io.Copy(f, c);
+ n, err1 := io.Copy(c, f);
fmt.Fprintf(c, "[%d bytes]\n", n);
f.Close();
}
fmt.Fprintf(c, "fork/exec: %s\n", err);
return;
}
- io.Copy(r, c);
+ io.Copy(c, r);
wait, err := os.Wait(pid, 0);
if err != nil {
fmt.Fprintf(c, "wait: %s\n", err);
// Copyn copies n bytes (or until an error) from src to dst.
// It returns the number of bytes copied and the error, if any.
-func Copyn(src Reader, dst Writer, n int64) (written int64, err os.Error) {
+func Copyn(dst Writer, src Reader, n int64) (written int64, err os.Error) {
buf := make([]byte, 32*1024);
for written < n {
l := len(buf);
// Copy copies from src to dst until either EOF is reached
// on src or an error occurs. It returns the number of bytes
// copied and the error, if any.
-func Copy(src Reader, dst Writer) (written int64, err os.Error) {
+func Copy(dst Writer, src Reader) (written int64, err os.Error) {
buf := make([]byte, 32*1024);
for {
nr, er := src.Read(buf);
// ReadAll reads from r until an error or EOF and returns the data it read.
func ReadAll(r Reader) ([]byte, os.Error) {
var buf bytes.Buffer;
- _, err := Copy(r, &buf);
+ _, err := Copy(&buf, r);
return buf.Bytes(), err;
}
w.Close();
var b bytes.Buffer;
- io.Copy(r, &b);
+ io.Copy(&b, r);
output := b.String();
expect := "/\n";
if output != expect {
w.Close();
var b bytes.Buffer;
- io.Copy(r, &b);
+ io.Copy(&b, r);
Wait(pid, 0);
output := b.String();
if n := len(output); n > 0 && output[n-1] == '\n' {