From 7ea52a8e4fd52e541c00757aa54a207db2c643ea Mon Sep 17 00:00:00 2001 From: Christoph Polcin Date: Thu, 17 May 2018 01:17:14 +0200 Subject: [PATCH] fix close --- README.md | 6 +++--- client.go | 3 +-- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index de7881d..08ec84a 100644 --- a/README.md +++ b/README.md @@ -165,7 +165,7 @@ func (c *Client) ReadDir(path string) ([]os.FileInfo, error) ``` ReadDir reads the contents of a remote directory -#### func (\*Client) [ReadStream](https://github.com/studio-b12/gowebdav/blob/master/client.go?s=6692:6755#L313) +#### func (\*Client) [ReadStream](https://github.com/studio-b12/gowebdav/blob/master/client.go?s=6691:6754#L312) ``` go func (c *Client) ReadStream(path string) (io.ReadCloser, error) ``` @@ -213,13 +213,13 @@ func (c *Client) Stat(path string) (os.FileInfo, error) ``` Stat returns the file stats for a specified path -#### func (\*Client) [Write](https://github.com/studio-b12/gowebdav/blob/master/client.go?s=7046:7115#L328) +#### func (\*Client) [Write](https://github.com/studio-b12/gowebdav/blob/master/client.go?s=7045:7114#L327) ``` go func (c *Client) Write(path string, data []byte, _ os.FileMode) error ``` Write writes data to a given path -#### func (\*Client) [WriteStream](https://github.com/studio-b12/gowebdav/blob/master/client.go?s=7517:7597#L350) +#### func (\*Client) [WriteStream](https://github.com/studio-b12/gowebdav/blob/master/client.go?s=7516:7596#L349) ``` go func (c *Client) WriteStream(path string, stream io.Reader, _ os.FileMode) error ``` diff --git a/client.go b/client.go index 562971a..dd9cbd7 100644 --- a/client.go +++ b/client.go @@ -295,11 +295,10 @@ func (c *Client) Read(path string) ([]byte, error) { var stream io.ReadCloser var err error - defer stream.Close() - if stream, err = c.ReadStream(path); err != nil { return nil, err } + defer stream.Close() buf := new(bytes.Buffer) _, err = buf.ReadFrom(stream)