package warp import ( "io" "github.com/portal-co/portald/floppy" ) type RW struct { Reader io.Reader Writer io.Writer } func (r RW) Read(p []byte) (n int, err error) { return r.Reader.Read(p) } func (r RW) Write(p []byte) (n int, err error) { return r.Writer.Write(p) } func XF2X(f func(io.ReadWriter) error) io.ReadWriter { ra, wa := io.Pipe() rb, wb := io.Pipe() go func() { err := f(RW{Reader: ra, Writer: wb}) if err == nil { err = io.EOF } ra.CloseWithError(err) wb.CloseWithError(err) }() return RW{Reader: rb, Writer: wa} } func X2XF(x io.ReadWriter) func(io.ReadWriter) error { return func(rw io.ReadWriter) error { return floppy.Floppy(x, rw) } }