Skip to content

Commit 29004d9

Browse files
committed
storer: change Open to return io.ReadCloser
In a future commit, we'll want to provide a storage interface that is read-only. If the Open method for storers returns a io.ReadWriteCloser, then we'll be forced to implement a useless Write method. Since we don't actually need the ability to call Write, simply make the storer interface return an io.ReadCloser instead, which lets us easily provide the read-only interface we want.
1 parent d53af9b commit 29004d9

File tree

3 files changed

+4
-4
lines changed

3 files changed

+4
-4
lines changed

file_storer.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,13 @@ func newFileStorer(root, tmp string) *fileStorer {
2727
}
2828
}
2929

30-
// Open implements the storer.Open function, and returns a io.ReadWriteCloser
30+
// Open implements the storer.Open function, and returns a io.ReadCloser
3131
// for the given SHA. If the file does not exist, or if there was any other
3232
// error in opening the file, an error will be returned.
3333
//
3434
// It is the caller's responsibility to close the given file "f" after its use
3535
// is complete.
36-
func (fs *fileStorer) Open(sha []byte) (f io.ReadWriteCloser, err error) {
36+
func (fs *fileStorer) Open(sha []byte) (f io.ReadCloser, err error) {
3737
return fs.open(fs.path(sha), os.O_RDONLY)
3838
}
3939

memory_storer.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ func (ms *memoryStorer) Store(sha []byte, r io.Reader) (n int64, err error) {
5151
// Open implements the storer.Open function, and returns a io.ReadWriteCloser
5252
// for the given SHA. If a reader for the given SHA does not exist an error will
5353
// be returned.
54-
func (ms *memoryStorer) Open(sha []byte) (f io.ReadWriteCloser, err error) {
54+
func (ms *memoryStorer) Open(sha []byte) (f io.ReadCloser, err error) {
5555
ms.mu.Lock()
5656
defer ms.mu.Unlock()
5757

storer.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import "io"
77
type storer interface {
88
// Open returns a handle on an existing object keyed by the given SHA.
99
// It returns an error if that file does not already exist.
10-
Open(sha []byte) (f io.ReadWriteCloser, err error)
10+
Open(sha []byte) (f io.ReadCloser, err error)
1111

1212
// Store copies the data given in "r" to the unique object path given by
1313
// "sha". It returns an error if that file already exists (acting as if

0 commit comments

Comments
 (0)