1
0
mirror of https://github.com/golang/go synced 2024-11-07 02:56:11 -07:00
Commit Graph

64 Commits

Author SHA1 Message Date
Lars Lehtonen
a866b48e4a io/ioutil: Fix dropped test error
Change-Id: I9cfaba4f1af23ab67627bf496739311e4d1984c3
Reviewed-on: https://go-review.googlesource.com/c/go/+/205245
Reviewed-by: Robert Griesemer <gri@golang.org>
Run-TryBot: Robert Griesemer <gri@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
2019-11-05 03:27:26 +00:00
Jason A. Donenfeld
16f0f9c8e1 syscall: respect permission bits on file opening on Windows
On Windows, os.Chmod and syscall.Chmod toggle the FILE_ATTRIBUTES_
READONLY flag depending on the permission bits. That's a bit odd but I
guess some compromises were made at some point and this is what was
chosen to map to a Unix concept that Windows doesn't really have in the
same way. That's fine. However, the logic used in Chmod was forgotten
from os.Open and syscall.Open, which then manifested itself in various
places, most recently, go modules' read-only behavior.

This makes syscall.Open consistent with syscall.Chmod and adds a test
for the permission _behavior_ using ioutil. By testing the behavior
instead of explicitly testing for the attribute bits we care about, we
make sure this doesn't regress in unforeseen ways in the future, as well
as ensuring the test works on platforms other than Windows.

In the process, we fix some tests that never worked and relied on broken
behavior, as well as tests that were disabled on Windows due to the
broken behavior and had TODO notes.

Fixes #35033

Change-Id: I6f7cf54517cbe5f6b1678d1c24f2ab337edcc7f7
Reviewed-on: https://go-review.googlesource.com/c/go/+/202439
Run-TryBot: Jason A. Donenfeld <Jason@zx2c4.com>
Reviewed-by: Bryan C. Mills <bcmills@google.com>
Reviewed-by: Alex Brainman <alex.brainman@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
2019-10-22 10:09:39 +00:00
sandyskies
03978a97e5 io: make CopyBuffer docs state when buf is not used
Document that if either src implements the WriteTo interface
or if dst implements the ReaderFrom interface, then
buf will not be used.

Fixes #32276

Change-Id: Id0a69c90e255e694e7ec9f79ffe4d8391441e59e
GitHub-Last-Rev: 750e7e86d5
GitHub-Pull-Request: golang/go#32279
Reviewed-on: https://go-review.googlesource.com/c/go/+/179137
Reviewed-by: Emmanuel Odeke <emm.odeke@gmail.com>
2019-10-21 17:47:24 +00:00
Emmanuel T Odeke
2718789bc7 io/ioutil: support predictable prefix,suffix for TempDir with *
Allow TempDir to create directories with predictable
prefixes and suffixes, separated by the last "*", for example:
    "prefix*suffix"
will now expand to
    "prefix" + <RANDOM_VALUE> + "suffix"

RELNOTE=yes

Fixes #33805.

Change-Id: I85fa73ae6a684ce820d1810c82a60765eb9c4a42
Reviewed-on: https://go-review.googlesource.com/c/go/+/198488
Run-TryBot: Emmanuel Odeke <emm.odeke@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
2019-10-16 20:38:29 +00:00
jsign
d15dfdc023 io/ioutil: don't check for short write in WriteFile
*os.File already does it.

Fixes #33064

Change-Id: I3edf0a31bf6d6e5023f47f01ebc92ed057357278
GitHub-Last-Rev: e6a5ba45d7
GitHub-Pull-Request: golang/go#33065
Reviewed-on: https://go-review.googlesource.com/c/go/+/185857
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
2019-09-01 02:31:50 +00:00
Jordi Martin
f45eb9ff3c io: add error check on pipe close functions to avoid error overwriting
The current implementation allows multiple calls `Close` and `CloseWithError` in every side of the pipe, as a result, the original error can be overwritten.

This CL fixes this behavior adding an error existence check on `atomicError` type
and keeping the first error still available.

Fixes #24283

Change-Id: Iefe8f758aeb775309424365f8177511062514150
GitHub-Last-Rev: b559540d7a
GitHub-Pull-Request: golang/go#33239
Reviewed-on: https://go-review.googlesource.com/c/go/+/187197
Reviewed-by: Joe Tsai <thebrokentoaster@gmail.com>
Run-TryBot: Joe Tsai <thebrokentoaster@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
2019-08-28 18:35:24 +00:00
Derek Phan
337662f7ca io: align style of test comments in multi_test.go
Change-Id: Ic93a084311de46461ed3b30f4ac2fe11311e74d7
GitHub-Last-Rev: 32fbd63b10
GitHub-Pull-Request: golang/go#29705
Reviewed-on: https://go-review.googlesource.com/c/157642
Run-TryBot: Daniel Martí <mvdan@mvdan.cc>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Matt Layher <mdlayher@gmail.com>
2019-02-26 23:01:20 +00:00
Daniel Martí
112f28defc io: export StringWriter
And start using it elsewhere in the standard library, removing the
copies in the process.

While at it, rewrite the io.WriteString godoc to be more clear, since it
can now make reference to the defined interface.

Fixes #27946.

Change-Id: Id5ba223c09c19e5fb49815bd3b1bd3254fc786f3
Reviewed-on: https://go-review.googlesource.com/c/139457
Run-TryBot: Daniel Martí <mvdan@mvdan.cc>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
2018-10-03 20:13:35 +00:00
G. Hussain Chinoy
f882d89b76 ghchinoy: add example for ioutil.WriteFile
Change-Id: I65c3bda498562fdf39994ec1cadce7947e2d84b5
Reviewed-on: https://go-review.googlesource.com/132277
Run-TryBot: Bryan C. Mills <bcmills@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Bryan C. Mills <bcmills@google.com>
2018-08-30 18:38:34 +00:00
Author Name
15ac56fd60 io: calculate buffer size only when needed
Change-Id: I930be9027fb972198b3d44816a5e4f53ff7eb5ea
Reviewed-on: https://go-review.googlesource.com/111642
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
2018-05-06 15:52:31 +00:00
Tom Limoncelli
191efbc419 io/ioutil: change TempFile prefix to a pattern
Users of TempFile need to be able to supply the suffix, especially
when using operating systems that give semantic meaning to the
filename extension such as Windows.  Renaming the file to include
an extension after the fact is insufficient as it could lead to
race conditions.

If the string given to TempFile includes a "*", the random string
replaces the "*". For example "myname.*.bat" will result in a random
filename such as "myname.123456.bat".  If no "*' is included the
old behavior is retained, and the random digits are appended to the
end.

If multiple "*" are included, the final one is replaced, thus
permitting a pathological programmer to create filenames such as
"foo*.123456.bat" but not "foo.123456.*.bat"

Fixes #4896

Change-Id: Iae7f0980b4de6d7d31b87c8c3c3d40767b283c1f
Reviewed-on: https://go-review.googlesource.com/105675
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
2018-04-12 20:00:25 +00:00
Agniva De Sarker
665af046c2 io: document that ReadAtLeast and ReadFull can drop errors
Add a note that if an error is returned after having read
at least the minimum no. of bytes, the error is set to nil.

Fixes #20477

Change-Id: I75ba5ee967be3ff80249e40d459da4afeeb53463
Reviewed-on: https://go-review.googlesource.com/102459
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2018-03-26 17:38:36 +00:00
Russ Cox
7781fed24e io: eliminate full copy of copy loop in CopyN
CL 60630 claimed to and did “improve performance of CopyN”
but in doing so introduced a second copy of the I/O copying loop.
This code is subtle and easy to get wrong and the last thing we
need is of two copies that can drift out of sync. Even the newly
introduced copy contains various subtle changes that are not
obviously semantically equivalent to the original. (They probably
are, but it's not obvious.)

Although the CL description does not explain further what the
important optimization was, it appears that the most critical
one was not allocating a 32kB buffer for CopyN(w, r, 512).

This CL deletes the forked copy of copy and instead applies
the buffer size restriction optimization directly to copy itself.

CL 60630 reported:

name          old time/op    new time/op    delta
CopyNSmall-4    5.09µs ± 1%    2.25µs ±86%  -55.91%  (p=0.000 n=11+14)
CopyNLarge-4     114µs ±73%     121µs ±72%     ~     (p=0.701 n=14+14)

Starting with that CL as the baseline, this CL does not change a ton:

name          old time/op  new time/op  delta
CopyNSmall-8   370ns ± 1%   411ns ± 1%  +11.18%  (p=0.000 n=16+14)
CopyNLarge-8  18.2µs ± 1%  18.3µs ± 1%   +0.63%  (p=0.000 n=19+20)

It does give up a small amount of the win of 60630 but preserves
the bulk of it, with the benefit that we will not need to debug these
two copies drifting out of sync in the future.

Change-Id: I05b1a5a7115390c5867847cba606b75d513eb2e2
Reviewed-on: https://go-review.googlesource.com/78122
Run-TryBot: Russ Cox <rsc@golang.org>
Reviewed-by: Joe Tsai <thebrokentoaster@gmail.com>
2017-11-16 02:24:37 +00:00
Russ Cox
e671a552fe io: document and test MultiWriter error behavior
MultiWriter(w1, w2) only writes to w2 if w1.Write succeeds.
I did not know this, and it was not documented.
Document and test.

Change-Id: Idec2e8444d5a7aca0b95d07814a28daa454eb1d3
Reviewed-on: https://go-review.googlesource.com/78123
Run-TryBot: Russ Cox <rsc@golang.org>
Reviewed-by: Joe Tsai <thebrokentoaster@gmail.com>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2017-11-15 21:27:42 +00:00
Joe Tsai
af37332d16 io: fix Pipe regression with differing error types
Usage of atomic.Value has a subtle requirement that the
value be of the same concrete type. In prior usage, the intention
was to consistently store a value of the error type.
Since error is an interface, the underlying concrete can differ.

Fix this by creating a type-safe abstraction over atomic.Value
that wraps errors in a struct{error} type to ensure consistent types.

Change-Id: Ica74f2daba15e4cff48d2b4f830d2cb51c608fb6
Reviewed-on: https://go-review.googlesource.com/75594
Run-TryBot: Joe Tsai <thebrokentoaster@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
2017-11-02 23:05:53 +00:00
Michael Fraenkel
060d1a5740 io: flatten MultiWriter writers
Replace any nested Writer that is a MultiWriter with its associated
Writers.

Fixes #22431

Change-Id: Ida7c4c83926363c1780689e216cf0c5241a5b8eb
Reviewed-on: https://go-review.googlesource.com/73470
Run-TryBot: Ian Lance Taylor <iant@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
2017-10-25 21:48:50 +00:00
Joe Tsai
371eda4558 io: simplify pipe implementation
In the distant past, Pipe was implemented with channels and a
long running pipe.run goroutine (see CL 994043).
This approach of having all communication serialized through the
run method was error prone giving Pipe a history of deadlocks
and race conditions.

After the introduction of sync.Cond, the implementation was rewritten
(see CL 4252057) to use condition variables and avoid the
long running pipe.run goroutine. While this implementation is superior
to the previous one, this implementation is strange in that the
p.data field is always set immediately prior to signaling the other
goroutine with Cond.Signal, effectively making the combination of the
two a channel-like operation. Inferior to a channel, however, this still
requires explicit locking around the p.data field.

The data+rwait can be effectively be replaced by a "chan []byte" to
inform a reader that there is data available.
The data+wwait can be effectively be replaced by a "chan int" to
inform a writer of how many bytes were read.

This implementation is a simplified from net.Pipe in CL 37402.

Change-Id: Ia5b26320b0525934fd87a3b69a091c787167f5aa
Reviewed-on: https://go-review.googlesource.com/65330
Run-TryBot: Joe Tsai <thebrokentoaster@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Bryan Mills <bcmills@google.com>
2017-10-11 20:00:54 +00:00
Albert Nigmatzianov
36e1c7ab73 io: Add benchmarks for CopyN
Copied from CL 60630

Current results:
name          time/op
CopyNSmall-4  2.20µs ±90%
CopyNLarge-4   136µs ±56%

name          alloc/op
CopyNSmall-4  1.84kB ±21%
CopyNLarge-4   128kB ±10%

name          allocs/op
CopyNSmall-4    1.00 ± 0%
CopyNLarge-4    1.00 ± 0%

Change-Id: If08c0132a773e936c9f61bff96e0aabf58006d31
Reviewed-on: https://go-review.googlesource.com/64932
Run-TryBot: Ian Lance Taylor <iant@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
2017-09-20 15:00:31 +00:00
Albert Nigmatzianov
098eb01600 io: Improve performance of CopyN
Benchmarks:
name          old time/op    new time/op    delta
CopyNSmall-4    5.09µs ± 1%    2.25µs ±86%  -55.91%  (p=0.000 n=11+14)
CopyNLarge-4     114µs ±73%     121µs ±72%     ~     (p=0.701 n=14+14)

name          old alloc/op   new alloc/op   delta
CopyNSmall-4    34.6kB ± 0%     1.9kB ±19%  -94.60%  (p=0.000 n=12+14)
CopyNLarge-4     129kB ± 8%     127kB ±18%   -2.00%  (p=0.007 n=14+14)

name          old allocs/op  new allocs/op  delta
CopyNSmall-4      2.00 ± 0%      1.00 ± 0%  -50.00%  (p=0.000 n=14+14)
CopyNLarge-4      2.00 ± 0%      1.00 ± 0%  -50.00%  (p=0.000 n=14+14)

Benchmark code:
type Buffer struct {
	bytes.Buffer
	io.ReaderFrom
}

func BenchmarkCopyNSmall(b *testing.B) {
	bs := bytes.Repeat([]byte{0}, 1024)
	rd := bytes.NewReader(bs)
	buf := new(Buffer)
	b.ResetTimer()

	for i := 0; i < b.N; i++ {
		io.CopyN(buf, rd, 512)
		rd.Reset(bs)
	}
}

func BenchmarkCopyNLarge(b *testing.B) {
	bs := bytes.Repeat([]byte{0}, 64*1024)
	rd := bytes.NewReader(bs)
	buf := new(Buffer)
	b.ResetTimer()

	for i := 0; i < b.N; i++ {
		io.CopyN(buf, rd, (32*1024)+1)
		rd.Reset(bs)
	}
}

Change-Id: Id8d29e55758452c870cf372db640f07baec05849
Reviewed-on: https://go-review.googlesource.com/60630
Run-TryBot: Ian Lance Taylor <iant@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
2017-09-20 13:41:50 +00:00
Bryan C. Mills
1d07ed1579 io/ioutil: don't cap buffer size in ReadFile
When we added a Stat call to determine the initial buffer size in
https://golang.org/cl/163069, we included an arbitrary 1e9-byte limit
"just in case". That interacts badly with power-of-2 resizing in
*bytes.Buffer: it causes buffers reading from very large files to
consume up to twice the necessary space.

The documentation for (os.FileInfo).Size says that it reports "length
in bytes for regular files; system-dependent for others", but the
"system dependent" cases overwhelmingly return either a small number
(e.g., the length of the target path for a symlink) or a non-positive
number (e.g., for a file in /proc under Linux). It should be
appropriate to use the number reported by Size as an approximate lower
bound, even if it is large.

fixes #21455

Change-Id: I609c72519b7b87428c24d0b22db46eede30e0e54
Reviewed-on: https://go-review.googlesource.com/55870
Reviewed-by: Ian Lance Taylor <iant@golang.org>
Reviewed-by: Joe Tsai <thebrokentoaster@gmail.com>
Run-TryBot: Ian Lance Taylor <iant@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
2017-08-31 19:32:18 +00:00
Guilherme Rezende
5e5a1ed88d io: add example for Pipe
Change-Id: I24374accf48d43edf4bf27ea6ba2245ddca558ad
Reviewed-on: https://go-review.googlesource.com/50910
Reviewed-by: Giovanni Bajo <rasky@develer.com>
Reviewed-by: Joe Tsai <thebrokentoaster@gmail.com>
Run-TryBot: Joe Tsai <thebrokentoaster@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
2017-08-22 19:42:20 +00:00
Vitor De Mario
42aec4c038 io/ioutil: add example for ReadFile
Change-Id: I062ec0606a741c8aa1b74f3f4b4e4fd47f76fed5
Reviewed-on: https://go-review.googlesource.com/48775
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
2017-07-15 23:28:44 +00:00
Greg Poirier
0a633c3bbe io: Add example to io.Seeker's Seek() method.
While there's an example for SectionReader.Seek, if someone is
seeking documentation specifically about Seeker.Seek, they may
not immediately find the SectionReader example. Offset and whence
may not be entirely intuitive to new developers either, so include
examples of both positive/negative offsets and SeekStart/SeekEnd.

Change-Id: I5b7442ccf683d9706e9261c11bc0ea31a1ac21d4
Reviewed-on: https://go-review.googlesource.com/48873
Reviewed-by: Kevin Burke <kev@inburke.com>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
2017-07-15 19:36:41 +00:00
smasher164
7e99ccb52b io: clarify documentation for io.ByteReader on error values
Document that the byte value returned by ReadByte() is meaningless
if its error != nil. Because io.Reader and io.ByteReader are similar in
name, this CL aims to clear up any ambiguity surrounding the returned
values, particularly where io.Reader is allowed to return both a
non-zero number of valid bytes and err == EOF.

Fixes #20825

Change-Id: I3a23c18c80c471c0caae3b4d2f6f8e547da0bed9
Reviewed-on: https://go-review.googlesource.com/46950
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2017-06-29 23:03:18 +00:00
David Lazar
46ecac99fb io: correctly compute call depth in test
TestMultiReaderFlatten determines the call depth by counting PCs
returned by runtime.Callers. With inlining, this is incorrect because
a PC can represent multiple calls. Furthermore, runtime.Callers might
return an additional "skip" PC, which does not represent a real call.
This modifies the test to use CallersFrames to determine the call depth.
Now the test passes with -l=4.

Change-Id: I284f3b1e0b2d194bd08c230c616914503e5a370d
Reviewed-on: https://go-review.googlesource.com/40990
Run-TryBot: David Lazar <lazard@golang.org>
Reviewed-by: Austin Clements <austin@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
2017-04-18 19:56:54 +00:00
Mostyn Bramley-Moore
2c1bff6e06 io/ioutil: make TestTempFile more robust
The first part of this test tries to confirm that we can't create
a TempFile in a non-existent directory, but does not ensure that
the non-existent directory really does not exist.  Instead, let's
create an empty temp directory, and use a non-existent subdir of
that.

Change-Id: I176f14ed5f5a2d7a8c29d8f6949755db69d7dbb6
Reviewed-on: https://go-review.googlesource.com/40914
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
2017-04-17 19:45:37 +00:00
David Lazar
f395e87888 io: fix test when MultiReader is inlined with -l=3
This ensures there isn't a live reference to buf1 on our stack
when MultiReader is inlined.

Fixes #18819.

Change-Id: I96a8cdc1ffad8f8a10c0ddcbf0299005f3176b61
Reviewed-on: https://go-review.googlesource.com/35931
Run-TryBot: David Lazar <lazard@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Austin Clements <austin@google.com>
Reviewed-by: Russ Cox <rsc@golang.org>
2017-02-02 18:56:20 +00:00
Kirill Smelkov
d296c3235d io: fix PipeWriter.Close to wake up Writes
Since commit cc62bed0 (CL 994043) the pipe deadlock when doing
Read+Close or Write+Close on same end was fixed, alas with test for
Read+Close case only.

Then commit 6d6f3381 (CL 4252057) made a thinko: in the writer path
p.werr is checked for != nil and then err is set but there is no break
from waiting loop unlike break is there in similar condition for reader.
Together with having only Read+Close case tested that made it to leave
reintroduced Write+Close deadlock unnoticed.

Fix it.

Implicitly this also fixes net.Pipe to conform to semantic of net.Conn
interface where Close is documented to unblock any blocked Read or Write
operations.

No test added to net/ since net.Pipe tests are "Assuming that the
underlying io.Pipe implementation is solid and we're just testing the
net wrapping". The test added in this patch should be enough to cover
the breakage.

Fixes #18401
Updates #18170

Change-Id: I9e9460b3fd7d220bbe60b726accf86f352aed8d4
Reviewed-on: https://go-review.googlesource.com/34637
Run-TryBot: Russ Cox <rsc@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Russ Cox <rsc@golang.org>
2016-12-21 15:08:26 +00:00
Joe Tsai
8c190e5854 io: update documentation on LimitedReader
Specify that that LimitedReader returns EOF when the underlying
R returns EOF even if bytes remaining, N > 0.

Fixes #18271

Change-Id: I990a7135f1d31488d535238ae061d42ee96bacb7
Reviewed-on: https://go-review.googlesource.com/34249
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2016-12-09 23:19:06 +00:00
Joe Tsai
291254414b io: fix MultiReader panic on nil reader.
The combination of two prior CLs can cause panics:
* CL/17873: make chained multiReader Read more efficient
* CL/28533: make MultiReader nil exhausted Readers for earlier GC

The first CL allows MultiReader to "inherit" another MultiReader's list of Readers
for efficiency reasons. This is problematic when combined with the
later CL since that can set prior Readers in that list to nil for GC reasons.
This causes panics when two MultiReaders are used together (even synchronously).

To fix this, rather than setting consumed Readers as nil, we set them with
a special eofReader that always returns EOF.

Fixes #18232

Change-Id: I2a9357ab217e3d54d38ea9022d18e4d14f4182d3
Reviewed-on: https://go-review.googlesource.com/34140
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
2016-12-08 17:29:33 +00:00
Russ Cox
427674fa0e io: clarify Pipe docs
Fixes #14139.

Change-Id: I6d2181720c38582b3d2160e94c7593a6cb4fc60f
Reviewed-on: https://go-review.googlesource.com/31321
Reviewed-by: Ian Lance Taylor <iant@golang.org>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2016-10-18 12:53:56 +00:00
Anmol Sethi
334cbe3bc8 io: simplified a small part of copyBuffer
Change-Id: I0b7052103174f0864ee9714f76f8f78f2a988777
Reviewed-on: https://go-review.googlesource.com/30719
Reviewed-by: Joe Tsai <thebrokentoaster@gmail.com>
Run-TryBot: Joe Tsai <thebrokentoaster@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
2016-10-09 22:50:12 +00:00
Brad Fitzpatrick
ad26bb5e30 all: use sort.Slice where applicable
I avoided anywhere in the compiler or things which might be used by
the compiler in the future, since they need to build with Go 1.4.

I also avoided anywhere where there was no benefit to changing it.

I probably missed some.

Updates #16721

Change-Id: Ib3c895ff475c6dec2d4322393faaf8cb6a6d4956
Reviewed-on: https://go-review.googlesource.com/30250
TryBot-Result: Gobot Gobot <gobot@golang.org>
Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org>
Reviewed-by: Andrew Gerrand <adg@golang.org>
2016-10-04 05:10:56 +00:00
Brad Fitzpatrick
fd975c6aa5 io/ioutil: return better error when TempDir called with non-extant dir
Fixes #14196

Change-Id: Ife7950289ac6adbcfc4d0f2fce31f20bc2657858
Reviewed-on: https://go-review.googlesource.com/28772
Reviewed-by: Ian Lance Taylor <iant@golang.org>
Run-TryBot: Ian Lance Taylor <iant@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
2016-09-08 15:08:35 +00:00
Brad Fitzpatrick
614dfe9b02 io: add test that MultiReader zeros exhausted Readers
Updates #16983
Updates #16996

Change-Id: I76390766385b2668632c95e172b2d243d7f66651
Reviewed-on: https://go-review.googlesource.com/28771
Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Keith Randall <khr@golang.org>
2016-09-08 02:55:54 +00:00
Brad Fitzpatrick
269ff8e603 io: make MultiReader nil exhausted Readers for earlier GC
No test because the language spec makes no promises in this area.

Fixes #16983

Change-Id: I1a6aa7ff87dd14aa27e8400040a6f6fc908aa1fd
Reviewed-on: https://go-review.googlesource.com/28533
Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Keith Randall <khr@golang.org>
Reviewed-by: Joe Tsai <thebrokentoaster@gmail.com>
2016-09-05 21:13:11 +00:00
Brad Fitzpatrick
e8ba80fbf6 io: fix comment in test
Updates #16795

Change-Id: I0bcc34bb5a92a2c480aebfb0eb6ba57bcc7f7cfd
Reviewed-on: https://go-review.googlesource.com/27551
Reviewed-by: Ian Lance Taylor <iant@golang.org>
2016-08-22 22:27:59 +00:00
Brad Fitzpatrick
93372673ce io: fix infinite loop bug in MultiReader
If an io.Reader returned (non-zero, EOF), MultiReader would yield
bytes forever.

This bug has existed before Go 1 (!!), introduced in the original
MultiReader implementation in https://golang.org/cl/1764043 and also
survived basically the only update to this code since then
(https://golang.org/cl/17873, git rev ccdca832c), which was added in
Go 1.7.

This just bit me when writing a test for some unrelated code.

Fixes #16795

Change-Id: I36e6a701269793935d19a47ac12f67b07179fbff
Reviewed-on: https://go-review.googlesource.com/27397
Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Keith Randall <khr@golang.org>
Reviewed-by: Joe Tsai <thebrokentoaster@gmail.com>
2016-08-19 19:14:02 +00:00
Joe Tsai
b859a78e0a io: use SeekStart, SeekCurrent, and SeekEnd in io.Seeker documentation
The documentation previously used C style enumerations: 0, 1, 2.
While this is pretty much universally correct, it does not help a user
become aware of the existence of the SeekStart, SeekCurrent, and SeekEnd
constants. Thus, we should use them in the documentation to direct people's
attention to them.

Updates #6885

Change-Id: I44b5e78d41601c68a0a1c96428c853df53981d52
Reviewed-on: https://go-review.googlesource.com/23551
Reviewed-by: Andrew Gerrand <adg@golang.org>
2016-05-29 06:52:45 +00:00
Russ Cox
524956f8b9 io: remove SizedReaderAt
It's not clear we want to enshrine an io interface in which Size cannot
return an error. Because this requires more thought before committing
to the API, remove from Go 1.7.

Fixes #15818.

Change-Id: Ic4138ffb0e033030145a12d33f78078350a8381f
Reviewed-on: https://go-review.googlesource.com/23392
Reviewed-by: Austin Clements <austin@google.com>
Run-TryBot: Russ Cox <rsc@golang.org>
2016-05-24 15:37:27 +00:00
andrew werner
ccdca832c5 io: make chained multiReader Read more efficient
before this change, when io.MultiReader was called many times but contain few
underlying readers, calls to Read were unnecessarily expensive.

Fixes #13558

Change-Id: I3ec4e88c7b50c075b148331fb1b7348a5840adbe
Reviewed-on: https://go-review.googlesource.com/17873
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
2016-05-16 22:55:42 +00:00
Joe Tsai
acc757f678 all: use SeekStart, SeekCurrent, SeekEnd
CL/19862 (f79b50b8d5) recently introduced the constants
SeekStart, SeekCurrent, and SeekEnd to the io package. We should use these constants
consistently throughout the code base.

Updates #15269

Change-Id: If7fcaca7676e4a51f588528f5ced28220d9639a2
Reviewed-on: https://go-review.googlesource.com/22097
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
Run-TryBot: Joe Tsai <joetsai@digital-static.net>
TryBot-Result: Gobot Gobot <gobot@golang.org>
2016-05-06 00:10:41 +00:00
Dan Peterson
c9b66bb355 io: document WriteString calls Write exactly once
Fixes #13849

Change-Id: Idd7f06b547a0179fe15571807a8c48b7c3b78d7c
Reviewed-on: https://go-review.googlesource.com/21852
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2016-04-12 01:03:51 +00:00
Rob Pike
01360a64c5 io: change the name of ReadAtSizer to SizedReaderAt
This is a proposal. The old name is pretty poor. The new one describes
it better and may be easier to remember. It does not start with Read,
though I think that inconsistency is worthwhile.

Reworded the comment a bit for clarity.

Change-Id: Icb4f9c663cc68958e0363d7ff78a0b29cc521f98
Reviewed-on: https://go-review.googlesource.com/21629
Reviewed-by: Andrew Gerrand <adg@golang.org>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2016-04-08 14:46:19 +00:00
Brad Fitzpatrick
7f39f21c7b io: add ReadAtSizer interface
ReadAtSizer is a common abstraction for a stateless,
concurrently-readable fixed number of bytes.

This interface has existed in various codebases for over 3 years (previously
usually named SizeReaderAt). It is used inside Google in dl.google.com
(mentioned in https://talks.golang.org/2013/oscon-dl.slide) and other
packages. It is used in Camlistore, in Juju, in the Google API Go client, in
github.com/nightlyone/views, and 33 other pages of Github search results.

It is implemented by io.SectionReader, bytes.Reader, strings.Reader, etc.

Time to finally promote this interface to the standard library and give it a
standard name, blessing it as best practice.

Updates #7263
Updates #14889

Change-Id: Id28c0cafa7d2d37e8887c54708b5daf1b11c83ea
Reviewed-on: https://go-review.googlesource.com/21492
Reviewed-by: Rob Pike <r@golang.org>
2016-04-06 04:02:49 +00:00
Eric Lagergren
acefcb732c io: define SeekStart, SeekCurrent, SeekEnd constants for use with Seeker
Fixes #6885

Change-Id: I6907958186f6a2427da1ad2f6c20bd5d7bf7a3f9
Reviewed-on: https://go-review.googlesource.com/19862
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2016-04-05 14:07:04 +00:00
Dominik Honnef
fdba5a7544 all: delete dead non-test code
This change removes a lot of dead code. Some of the code has never been
used, not even when it was first commited. The rest shouldn't have
survived refactors.

This change doesn't remove unused routines helpful for debugging, nor
does it remove code that's used in commented out blocks of code that are
only unused temporarily. Furthermore, unused constants weren't removed
when they were part of a set of constants from specifications.

One noteworthy omission from this CL are about 1000 lines of unused code
in cmd/fix, 700 lines of which are the typechecker, which hasn't been
used ever since the pre-Go 1 fixes have been removed. I wasn't sure if
this code should stick around for future uses of cmd/fix or be culled as
well.

Change-Id: Ib714bc7e487edc11ad23ba1c3222d1fd02e4a549
Reviewed-on: https://go-review.googlesource.com/20926
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
2016-03-25 06:28:13 +00:00
Brad Fitzpatrick
5fea2ccc77 all: single space after period.
The tree's pretty inconsistent about single space vs double space
after a period in documentation. Make it consistently a single space,
per earlier decisions. This means contributors won't be confused by
misleading precedence.

This CL doesn't use go/doc to parse. It only addresses // comments.
It was generated with:

$ perl -i -npe 's,^(\s*// .+[a-z]\.)  +([A-Z]),$1 $2,' $(git grep -l -E '^\s*//(.+\.)  +([A-Z])')
$ go test go/doc -update

Change-Id: Iccdb99c37c797ef1f804a94b22ba5ee4b500c4f7
Reviewed-on: https://go-review.googlesource.com/20022
Reviewed-by: Rob Pike <r@golang.org>
Reviewed-by: Dave Day <djd@golang.org>
Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
2016-03-02 00:13:47 +00:00
Brad Fitzpatrick
519474451a all: make copyright headers consistent with one space after period
This is a subset of https://golang.org/cl/20022 with only the copyright
header lines, so the next CL will be smaller and more reviewable.

Go policy has been single space after periods in comments for some time.

The copyright header template at:

    https://golang.org/doc/contribute.html#copyright

also uses a single space.

Make them all consistent.

Change-Id: Icc26c6b8495c3820da6b171ca96a74701b4a01b0
Reviewed-on: https://go-review.googlesource.com/20111
Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
2016-03-01 23:34:33 +00:00
Brad Fitzpatrick
351c15f1ce all: remove public named return values when useless
Named returned values should only be used on public funcs and methods
when it contributes to the documentation.

Named return values should not be used if they're only saving the
programmer a few lines of code inside the body of the function,
especially if that means there's stutter in the documentation or it
was only there so the programmer could use a naked return
statement. (Naked returns should not be used except in very small
functions)

This change is a manual audit & cleanup of public func signatures.

Signatures were not changed if:

* the func was private (wouldn't be in public godoc)
* the documentation referenced it
* the named return value was an interesting name. (i.e. it wasn't
  simply stutter, repeating the name of the type)

There should be no changes in behavior. (At least: none intended)

Change-Id: I3472ef49619678fe786e5e0994bdf2d9de76d109
Reviewed-on: https://go-review.googlesource.com/20024
Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Andrew Gerrand <adg@golang.org>
2016-02-29 03:31:19 +00:00