mirror of
https://github.com/moby/moby.git
synced 2022-11-09 12:21:53 -05:00
Use io.WriteCloser instead of *os.File in DockerLocalConn so we can use it with standard writers and pipes
This commit is contained in:
parent
246eed52de
commit
e6e9c1cd62
1 changed files with 10 additions and 6 deletions
|
@ -33,24 +33,28 @@ type DockerConn interface {
|
|||
}
|
||||
|
||||
type DockerLocalConn struct {
|
||||
file *os.File
|
||||
writer io.WriteCloser
|
||||
savedState *term.State
|
||||
}
|
||||
|
||||
func NewDockerLocalConn(output *os.File) *DockerLocalConn {
|
||||
return &DockerLocalConn{file: output}
|
||||
func NewDockerLocalConn(w io.WriteCloser) *DockerLocalConn {
|
||||
return &DockerLocalConn{
|
||||
writer: w,
|
||||
}
|
||||
}
|
||||
|
||||
func (c *DockerLocalConn) Read(b []byte) (int, error) { return c.file.Read(b) }
|
||||
func (c *DockerLocalConn) Read(b []byte) (int, error) {
|
||||
return 0, fmt.Errorf("DockerLocalConn does not implement Read()")
|
||||
}
|
||||
|
||||
func (c *DockerLocalConn) Write(b []byte) (int, error) { return c.file.Write(b) }
|
||||
func (c *DockerLocalConn) Write(b []byte) (int, error) { return c.writer.Write(b) }
|
||||
|
||||
func (c *DockerLocalConn) Close() error {
|
||||
if c.savedState != nil {
|
||||
RestoreTerminal(c.savedState)
|
||||
c.savedState = nil
|
||||
}
|
||||
return c.file.Close()
|
||||
return c.writer.Close()
|
||||
}
|
||||
|
||||
func (c *DockerLocalConn) CloseWrite() error { return nil }
|
||||
|
|
Loading…
Reference in a new issue