From 8e68e2b26e53c5b773c18abd33214b48e83d4247 Mon Sep 17 00:00:00 2001 From: Runxi Yu Date: Thu, 2 Apr 2026 07:15:59 +0000 Subject: common/iowrap: Add --- common/iowrap/doc.go | 2 ++ common/iowrap/write_flusher.go | 9 +++++++++ common/iowrap/write_flusher_nop.go | 21 +++++++++++++++++++++ 3 files changed, 32 insertions(+) create mode 100644 common/iowrap/doc.go create mode 100644 common/iowrap/write_flusher.go create mode 100644 common/iowrap/write_flusher_nop.go 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 +} -- cgit v1.3.1-10-gc9f91