aboutsummaryrefslogtreecommitdiffhomepage
path: root/common
diff options
context:
space:
mode:
Diffstat (limited to 'common')
-rw-r--r--common/hugio/writers.go30
1 files changed, 30 insertions, 0 deletions
diff --git a/common/hugio/writers.go b/common/hugio/writers.go
index 729b21715..6f439cc8b 100644
--- a/common/hugio/writers.go
+++ b/common/hugio/writers.go
@@ -81,3 +81,33 @@ func ToReadCloser(r io.Reader) io.ReadCloser {
io.NopCloser(nil),
}
}
+
+type ReadWriteCloser interface {
+ io.Reader
+ io.Writer
+ io.Closer
+}
+
+// PipeReadWriteCloser is a convenience type to create a pipe with a ReadCloser and a WriteCloser.
+type PipeReadWriteCloser struct {
+ *io.PipeReader
+ *io.PipeWriter
+}
+
+// NewPipeReadWriteCloser creates a new PipeReadWriteCloser.
+func NewPipeReadWriteCloser() PipeReadWriteCloser {
+ pr, pw := io.Pipe()
+ return PipeReadWriteCloser{pr, pw}
+}
+
+func (c PipeReadWriteCloser) Close() (err error) {
+ if err = c.PipeReader.Close(); err != nil {
+ return
+ }
+ err = c.PipeWriter.Close()
+ return
+}
+
+func (c PipeReadWriteCloser) WriteString(s string) (int, error) {
+ return c.PipeWriter.Write([]byte(s))
+}