diff options
Diffstat (limited to 'src/pkg/io')
-rw-r--r-- | src/pkg/io/io.go | 7 | ||||
-rw-r--r-- | src/pkg/io/ioutil/ioutil.go | 9 |
2 files changed, 13 insertions, 3 deletions
diff --git a/src/pkg/io/io.go b/src/pkg/io/io.go index 7074834d6..54bf159eb 100644 --- a/src/pkg/io/io.go +++ b/src/pkg/io/io.go @@ -173,6 +173,13 @@ type ReaderAt interface { // at offset off. It returns the number of bytes written from p (0 <= n <= len(p)) // and any error encountered that caused the write to stop early. // WriteAt must return a non-nil error if it returns n < len(p). +// +// If WriteAt is writing to a destination with a seek offset, +// WriteAt should not affect nor be affected by the underlying +// seek offset. +// +// Clients of WriteAt can execute parallel WriteAt calls on the same +// destination if the ranges do not overlap. type WriterAt interface { WriteAt(p []byte, off int64) (n int, err error) } diff --git a/src/pkg/io/ioutil/ioutil.go b/src/pkg/io/ioutil/ioutil.go index 180afc2c2..f072b8c75 100644 --- a/src/pkg/io/ioutil/ioutil.go +++ b/src/pkg/io/ioutil/ioutil.go @@ -53,10 +53,13 @@ func ReadFile(filename string) ([]byte, error) { defer f.Close() // It's a good but not certain bet that FileInfo will tell us exactly how much to // read, so let's try it but be prepared for the answer to be wrong. - fi, err := f.Stat() var n int64 - if size := fi.Size(); err == nil && size < 2e9 { // Don't preallocate a huge buffer, just in case. - n = size + + if fi, err := f.Stat(); err == nil { + // Don't preallocate a huge buffer, just in case. + if size := fi.Size(); size < 1e9 { + n = size + } } // As initial capacity for readAll, use n + a little extra in case Size is zero, // and to avoid another allocation after Read has filled the buffer. The readAll |