pkg/ioutils: deprecate NopFlusher

Apart from being used internally for NewWriteFlusher, it's only used
in a single location outside of this package. Copy the implementation
where it's used, and mark it deprecated.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
(cherry picked from commit 818a180fce)
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
This commit is contained in:
Sebastiaan van Stijn
2025-01-09 17:56:06 +01:00
parent d9c2cde3be
commit 41697f61ec
3 changed files with 15 additions and 6 deletions

View File

@@ -339,8 +339,12 @@ type flusher interface {
Flush()
}
type nopFlusher struct{}
func (f *nopFlusher) Flush() {}
func wrapOutputBufferedUntilRequestRead(rc io.ReadCloser, out io.Writer) (io.ReadCloser, io.Writer) {
var fl flusher = &ioutils.NopFlusher{}
var fl flusher = &nopFlusher{}
if f, ok := out.(flusher); ok {
fl = f
}

View File

@@ -80,13 +80,19 @@ func (wf *WriteFlusher) Close() error {
return nil
}
// nopFlusher represents a type which flush operation is nop.
type nopFlusher struct{}
// Flush is a nop operation.
func (f *nopFlusher) Flush() {}
// NewWriteFlusher returns a new WriteFlusher.
func NewWriteFlusher(w io.Writer) *WriteFlusher {
var fl flusher
if f, ok := w.(flusher); ok {
fl = f
} else {
fl = &NopFlusher{}
fl = &nopFlusher{}
}
return &WriteFlusher{w: w, flusher: fl, closed: make(chan struct{}), flushed: make(chan struct{})}
}

View File

@@ -24,10 +24,9 @@ func NopWriteCloser(w io.Writer) io.WriteCloser {
}
// NopFlusher represents a type which flush operation is nop.
type NopFlusher struct{}
// Flush is a nop operation.
func (f *NopFlusher) Flush() {}
//
// Deprecated: NopFlusher is only used internally and will be removed in the next release.
type NopFlusher = nopFlusher
type writeCloserWrapper struct {
io.Writer