]> Cypherpunks repositories - gostls13.git/commitdiff
io: add ReadAtSizer interface
authorBrad Fitzpatrick <bradfitz@golang.org>
Mon, 4 Apr 2016 16:54:54 +0000 (16:54 +0000)
committerBrad Fitzpatrick <bradfitz@golang.org>
Wed, 6 Apr 2016 04:02:49 +0000 (04:02 +0000)
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>
src/io/io.go

index 6e331920521ac2077ddc11d72e0104849e7df0b6..23401dae931032a4b227fe4216179e84333b179d 100644 (file)
@@ -274,6 +274,15 @@ type RuneScanner interface {
        UnreadRune() error
 }
 
+// ReadAtSizer is the interface that groups the basic ReadAt and Size
+// methods, representing a sized data source that supports random
+// access by multiple concurrent goroutines.
+type ReadAtSizer interface {
+       ReaderAt
+       // Size reports the length of the data source in bytes.
+       Size() int64
+}
+
 // stringWriter is the interface that wraps the WriteString method.
 type stringWriter interface {
        WriteString(s string) (n int, err error)