Skip to content

Commit b161ca7

Browse files
committed
storage: avoid io.NopCloser; it was relatively recently introduced.
(I think our policy is roughly "support the last two significant go versions", and by that, we might technically be allowed to use this, but, eh; there's minimal cost to being conservative today.)
1 parent 7a48106 commit b161ca7

File tree

2 files changed

+10
-6
lines changed

2 files changed

+10
-6
lines changed

storage/funcs.go

+5-3
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ func GetStream(ctx context.Context, store ReadableStorage, key string) (io.ReadC
4343
}
4444
// Fallback to basic.
4545
blob, err := store.Get(ctx, key)
46-
return io.NopCloser(bytes.NewReader(blob)), err
46+
return noopCloser{bytes.NewReader(blob)}, err
4747
}
4848

4949
// PutStream returns an io.Writer and a WriteCommitter callback.
@@ -112,9 +112,11 @@ func Peek(ctx context.Context, store ReadableStorage, key string) ([]byte, io.Cl
112112
}
113113
// Fallback to basic.
114114
bs, err := store.Get(ctx, key)
115-
return bs, noopCloser{}, err
115+
return bs, noopCloser{nil}, err
116116
}
117117

118-
type noopCloser struct{}
118+
type noopCloser struct {
119+
io.Reader
120+
}
119121

120122
func (noopCloser) Close() error { return nil }

storage/memstore/memstore.go

+5-3
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ func (store *Store) GetStream(ctx context.Context, key string) (io.ReadCloser, e
8484
if !exists {
8585
return nil, fmt.Errorf("404") // FIXME this needs a standard error type
8686
}
87-
return io.NopCloser(bytes.NewReader(content)), nil
87+
return noopCloser{bytes.NewReader(content)}, nil
8888
}
8989

9090
// Peek implements go-ipld-prime/storage.PeekableStorage.Peek.
@@ -93,9 +93,11 @@ func (store *Store) Peek(ctx context.Context, key string) ([]byte, io.Closer, er
9393
if !exists {
9494
return nil, nil, fmt.Errorf("404") // FIXME this needs a standard error type
9595
}
96-
return content, noopCloser{}, nil
96+
return content, noopCloser{nil}, nil
9797
}
9898

99-
type noopCloser struct{}
99+
type noopCloser struct {
100+
io.Reader
101+
}
100102

101103
func (noopCloser) Close() error { return nil }

0 commit comments

Comments
 (0)