Code Cleanup, rename outputbc to execbc, using buffered Writer

This commit is contained in:
Michael Reif
2024-01-06 09:32:47 +01:00
parent f65b18842a
commit cc6b8277c9
7 changed files with 98 additions and 66 deletions
+29
View File
@@ -0,0 +1,29 @@
package execbc
import (
"bufio"
"io"
"os/exec"
"github.com/AlexxIT/go2rtc/pkg/core"
)
type pipeCloser struct {
io.Writer
io.Closer
cmd *exec.Cmd
}
func PipeCloser(cmd *exec.Cmd) (io.WriteCloser, error) {
stdin, err := cmd.StdinPipe()
if err != nil {
return nil, err
}
return pipeCloser{bufio.NewWriterSize(stdin, 640), stdin, cmd}, nil
}
func (p pipeCloser) Close() (err error) {
return core.Any(p.Closer.Close(), p.cmd.Process.Kill(), p.cmd.Wait())
}