summaryrefslogtreecommitdiff
path: root/pkg/channelwriter
diff options
context:
space:
mode:
authorbaude <bbaude@redhat.com>2019-06-18 13:56:18 -0500
committerbaude <bbaude@redhat.com>2019-07-10 08:50:05 -0500
commit780b05610ecf9ea107ec69c913dd074d69c1dc88 (patch)
tree1231b5de06f6a6368926edb225a8aaf91775dcdb /pkg/channelwriter
parent81e722d08617ee19235bf57de6d86124e6b4574a (diff)
downloadpodman-780b05610ecf9ea107ec69c913dd074d69c1dc88.tar.gz
podman-780b05610ecf9ea107ec69c913dd074d69c1dc88.tar.bz2
podman-780b05610ecf9ea107ec69c913dd074d69c1dc88.zip
account for varlink calls that dont use more
the commit and pull varlink endpoints were not working correctly when 'more' was not being specified. Fixes: #3317 Fixes: #3318 Fixes: #3526 Signed-off-by: baude <bbaude@redhat.com>
Diffstat (limited to 'pkg/channelwriter')
-rw-r--r--pkg/channelwriter/channelwriter.go34
1 files changed, 34 insertions, 0 deletions
diff --git a/pkg/channelwriter/channelwriter.go b/pkg/channelwriter/channelwriter.go
new file mode 100644
index 000000000..d51400eb3
--- /dev/null
+++ b/pkg/channelwriter/channelwriter.go
@@ -0,0 +1,34 @@
+package channelwriter
+
+import "github.com/pkg/errors"
+
+// Writer is an io.writer-like object that "writes" to a channel
+// instead of a buffer or file, etc. It is handy for varlink endpoints when
+// needing to handle endpoints that do logging "real-time"
+type Writer struct {
+ ByteChannel chan []byte
+}
+
+// NewChannelWriter creates a new channel writer and adds a
+// byte slice channel into it.
+func NewChannelWriter() *Writer {
+ byteChannel := make(chan []byte)
+ return &Writer{
+ ByteChannel: byteChannel,
+ }
+}
+
+// Write method for Writer
+func (c *Writer) Write(w []byte) (int, error) {
+ if c.ByteChannel == nil {
+ return 0, errors.New("channel writer channel cannot be nil")
+ }
+ c.ByteChannel <- w
+ return len(w), nil
+}
+
+// Close method for Writer
+func (c *Writer) Close() error {
+ close(c.ByteChannel)
+ return nil
+}