Skip to content

Commit 4361cc1

Browse files
committed
Expose StreamerWriter interface
Streamer() now returns a StreamWriter interface (not io.ReadWriteCloser) so that the CloseWithError(error) method may be called without casting. The idiomatic name for this interface and function should be Streamer and NewStreamer(). However, the function is already named Streamer() and a package can't contain a function and interface with the same name, so we need to call it something else. I decided to name the interface StreamWriter, as writing is the primary use case for library callers.
1 parent abe3628 commit 4361cc1

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

buffer.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,11 @@ func (b *bufCloser) Close() error {
1414
return nil // No-op
1515
}
1616

17+
type StreamerWriter interface {
18+
io.ReadWriteCloser
19+
CloseWithError(error) error
20+
}
21+
1722
type streamer struct {
1823
pipeR *io.PipeReader
1924
pipeW *io.PipeWriter
@@ -35,7 +40,7 @@ type streamer struct {
3540
//
3641
// Note that a Streamer may not perform any internal buffering, so callers should take care not to depend on writes
3742
// being non-blocking. If buffering is needed, Streamer can be wrapped in a bufio.Writer.
38-
func Streamer() io.ReadWriteCloser {
43+
func Streamer() StreamerWriter {
3944
pipeR, pipeW := io.Pipe()
4045
return &streamer{
4146
pipeR: pipeR,

0 commit comments

Comments
 (0)