Removes WrapReader boilerplate for updates to libchan
libchan now supports io.ReadCloser and io.WriteCloser, so we don't need io.ReadWriteCloser wrapping
This commit is contained in:
parent
3e4738587f
commit
b522fbd675
3 changed files with 5 additions and 30 deletions
|
@ -155,7 +155,7 @@ func (driver *StorageDriverClient) GetContent(path string) ([]byte, error) {
|
||||||
func (driver *StorageDriverClient) PutContent(path string, contents []byte) error {
|
func (driver *StorageDriverClient) PutContent(path string, contents []byte) error {
|
||||||
receiver, remoteSender := libchan.Pipe()
|
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})
|
err := driver.sender.Send(&Request{Type: "PutContent", Parameters: params, ResponseChannel: remoteSender})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
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 {
|
func (driver *StorageDriverClient) WriteStream(path string, offset, size uint64, reader io.ReadCloser) error {
|
||||||
receiver, remoteSender := libchan.Pipe()
|
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})
|
err := driver.sender.Send(&Request{Type: "WriteStream", Parameters: params, ResponseChannel: remoteSender})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
|
|
|
@ -1,10 +1,8 @@
|
||||||
package ipc
|
package ipc
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"errors"
|
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"io/ioutil"
|
|
||||||
"reflect"
|
"reflect"
|
||||||
|
|
||||||
"github.com/docker/libchan"
|
"github.com/docker/libchan"
|
||||||
|
@ -18,29 +16,6 @@ type Request struct {
|
||||||
ResponseChannel libchan.Sender
|
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 responseError struct {
|
||||||
Type string
|
Type string
|
||||||
Message string
|
Message string
|
||||||
|
@ -65,7 +40,7 @@ func (err *responseError) Error() string {
|
||||||
|
|
||||||
// ReadStreamResponse is a response for a ReadStream request
|
// ReadStreamResponse is a response for a ReadStream request
|
||||||
type ReadStreamResponse struct {
|
type ReadStreamResponse struct {
|
||||||
Reader io.ReadWriteCloser
|
Reader io.ReadCloser
|
||||||
Error *responseError
|
Error *responseError
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -68,7 +68,7 @@ func handleRequest(driver storagedriver.StorageDriver, request Request) {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
response = ReadStreamResponse{Error: ResponseError(err)}
|
response = ReadStreamResponse{Error: ResponseError(err)}
|
||||||
} else {
|
} else {
|
||||||
response = ReadStreamResponse{Reader: WrapReader(bytes.NewReader(content))}
|
response = ReadStreamResponse{Reader: ioutil.NopCloser(bytes.NewReader(content))}
|
||||||
}
|
}
|
||||||
err = request.ResponseChannel.Send(&response)
|
err = request.ResponseChannel.Send(&response)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -98,7 +98,7 @@ func handleRequest(driver storagedriver.StorageDriver, request Request) {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
response = ReadStreamResponse{Error: ResponseError(err)}
|
response = ReadStreamResponse{Error: ResponseError(err)}
|
||||||
} else {
|
} else {
|
||||||
response = ReadStreamResponse{Reader: WrapReader(reader)}
|
response = ReadStreamResponse{Reader: ioutil.NopCloser(reader)}
|
||||||
}
|
}
|
||||||
err = request.ResponseChannel.Send(&response)
|
err = request.ResponseChannel.Send(&response)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
Loading…
Reference in a new issue