From 67af9d7223b0cc643025d958c592291f7475ac75 Mon Sep 17 00:00:00 2001 From: Máximo Cuadros Date: Sun, 2 May 2021 23:36:12 +0200 Subject: utils: ioutil, Pipe implementatio --- utils/ioutil/common.go | 12 +++++++++++- utils/ioutil/pipe.go | 9 +++++++++ utils/ioutil/pipe_js.go | 9 +++++++++ 3 files changed, 29 insertions(+), 1 deletion(-) create mode 100644 utils/ioutil/pipe.go create mode 100644 utils/ioutil/pipe_js.go (limited to 'utils') diff --git a/utils/ioutil/common.go b/utils/ioutil/common.go index e9dcbfe..b52e85a 100644 --- a/utils/ioutil/common.go +++ b/utils/ioutil/common.go @@ -7,7 +7,7 @@ import ( "errors" "io" - "github.com/jbenet/go-context/io" + ctxio "github.com/jbenet/go-context/io" ) type readPeeker interface { @@ -168,3 +168,13 @@ func (r *writerOnError) Write(p []byte) (n int, err error) { return } + +type PipeReader interface { + io.ReadCloser + CloseWithError(err error) error +} + +type PipeWriter interface { + io.WriteCloser + CloseWithError(err error) error +} diff --git a/utils/ioutil/pipe.go b/utils/ioutil/pipe.go new file mode 100644 index 0000000..f30c452 --- /dev/null +++ b/utils/ioutil/pipe.go @@ -0,0 +1,9 @@ +// +build !js + +package ioutil + +import "io" + +func Pipe() (PipeReader, PipeWriter) { + return io.Pipe() +} diff --git a/utils/ioutil/pipe_js.go b/utils/ioutil/pipe_js.go new file mode 100644 index 0000000..cf102e6 --- /dev/null +++ b/utils/ioutil/pipe_js.go @@ -0,0 +1,9 @@ +// +build js + +package ioutil + +import "github.com/acomagu/bufpipe" + +func Pipe() (PipeReader, PipeWriter) { + return bufpipe.New(nil) +} -- cgit