diff --git a/storagedriver/ipc/client.go b/storagedriver/ipc/client.go index cdac8b11..54090945 100644 --- a/storagedriver/ipc/client.go +++ b/storagedriver/ipc/client.go @@ -155,7 +155,7 @@ func (driver *StorageDriverClient) GetContent(path string) ([]byte, error) { func (driver *StorageDriverClient) PutContent(path string, contents []byte) error { receiver, remoteSender := libchan.Pipe() - params := map[string]interface{}{"Path": path, "Reader": WrapReader(bytes.NewReader(contents))} + params := map[string]interface{}{"Path": path, "Reader": ioutil.NopCloser(bytes.NewReader(contents))} err := driver.sender.Send(&Request{Type: "PutContent", Parameters: params, ResponseChannel: remoteSender}) if err != nil { return err @@ -199,7 +199,7 @@ func (driver *StorageDriverClient) ReadStream(path string, offset uint64) (io.Re func (driver *StorageDriverClient) WriteStream(path string, offset, size uint64, reader io.ReadCloser) error { receiver, remoteSender := libchan.Pipe() - params := map[string]interface{}{"Path": path, "Offset": offset, "Size": size, "Reader": WrapReader(reader)} + params := map[string]interface{}{"Path": path, "Offset": offset, "Size": size, "Reader": ioutil.NopCloser(reader)} err := driver.sender.Send(&Request{Type: "WriteStream", Parameters: params, ResponseChannel: remoteSender}) if err != nil { return err diff --git a/storagedriver/ipc/ipc.go b/storagedriver/ipc/ipc.go index 30f63393..9c6b1dc0 100644 --- a/storagedriver/ipc/ipc.go +++ b/storagedriver/ipc/ipc.go @@ -1,10 +1,8 @@ package ipc import ( - "errors" "fmt" "io" - "io/ioutil" "reflect" "github.com/docker/libchan" @@ -18,29 +16,6 @@ type Request struct { ResponseChannel libchan.Sender } -// noWriteReadWriteCloser is a simple wrapper around an io.ReadCloser that implements the -// io.ReadWriteCloser interface -// Calls to Write are disallowed and will return an error -type noWriteReadWriteCloser struct { - io.ReadCloser -} - -func (r noWriteReadWriteCloser) Write(p []byte) (n int, err error) { - return 0, errors.New("Write unsupported") -} - -// WrapReader wraps an io.Reader as an io.ReadWriteCloser with a nop Close and unsupported Write -// Has no effect when an io.ReadWriteCloser is passed in -func WrapReader(reader io.Reader) io.ReadWriteCloser { - if readWriteCloser, ok := reader.(io.ReadWriteCloser); ok { - return readWriteCloser - } else if readCloser, ok := reader.(io.ReadCloser); ok { - return noWriteReadWriteCloser{readCloser} - } else { - return noWriteReadWriteCloser{ioutil.NopCloser(reader)} - } -} - type responseError struct { Type string Message string @@ -65,7 +40,7 @@ func (err *responseError) Error() string { // ReadStreamResponse is a response for a ReadStream request type ReadStreamResponse struct { - Reader io.ReadWriteCloser + Reader io.ReadCloser Error *responseError } diff --git a/storagedriver/ipc/server.go b/storagedriver/ipc/server.go index 81432cc3..989b44ba 100644 --- a/storagedriver/ipc/server.go +++ b/storagedriver/ipc/server.go @@ -68,7 +68,7 @@ func handleRequest(driver storagedriver.StorageDriver, request Request) { if err != nil { response = ReadStreamResponse{Error: ResponseError(err)} } else { - response = ReadStreamResponse{Reader: WrapReader(bytes.NewReader(content))} + response = ReadStreamResponse{Reader: ioutil.NopCloser(bytes.NewReader(content))} } err = request.ResponseChannel.Send(&response) if err != nil { @@ -98,7 +98,7 @@ func handleRequest(driver storagedriver.StorageDriver, request Request) { if err != nil { response = ReadStreamResponse{Error: ResponseError(err)} } else { - response = ReadStreamResponse{Reader: WrapReader(reader)} + response = ReadStreamResponse{Reader: ioutil.NopCloser(reader)} } err = request.ResponseChannel.Send(&response) if err != nil {