diff options
| author | 2026-04-02 07:15:59 +0000 | |
|---|---|---|
| committer | 2026-04-02 07:15:59 +0000 | |
| commit | 8e68e2b26e53c5b773c18abd33214b48e83d4247 (patch) | |
| tree | c14ff59515a5611177963f68b7d5ac04533e96f1 | |
| parent | internal: Documentation (diff) | |
| signature | No signature | |
common/iowrap: Add
| -rw-r--r-- | common/iowrap/doc.go | 2 | ||||
| -rw-r--r-- | common/iowrap/write_flusher.go | 9 | ||||
| -rw-r--r-- | common/iowrap/write_flusher_nop.go | 21 |
3 files changed, 32 insertions, 0 deletions
diff --git a/common/iowrap/doc.go b/common/iowrap/doc.go new file mode 100644 index 00000000..8e25db16 --- /dev/null +++ b/common/iowrap/doc.go @@ -0,0 +1,2 @@ +// Package iowrap provides small public I/O wrapper interfaces and adapters. +package iowrap diff --git a/common/iowrap/write_flusher.go b/common/iowrap/write_flusher.go new file mode 100644 index 00000000..aaac8724 --- /dev/null +++ b/common/iowrap/write_flusher.go @@ -0,0 +1,9 @@ +package iowrap + +import "io" + +// WriteFlusher writes bytes and flushes buffered output state. +type WriteFlusher interface { + io.Writer + Flush() error +} diff --git a/common/iowrap/write_flusher_nop.go b/common/iowrap/write_flusher_nop.go new file mode 100644 index 00000000..91d30c3e --- /dev/null +++ b/common/iowrap/write_flusher_nop.go @@ -0,0 +1,21 @@ +package iowrap + +import "io" + +type nopFlusher struct { + io.Writer +} + +// NopFlush adapts writer into a [WriteFlusher] with a no-op Flush. +func NopFlush(writer io.Writer) WriteFlusher { + if writer == nil { + return nil + } + + return nopFlusher{Writer: writer} +} + +// Flush lets us satisfy [WriteFlusher] but does nothing. +func (nopFlusher) Flush() error { + return nil +} |
