From df102c9cec01900dc7731ae8a2257e940cafe318 Mon Sep 17 00:00:00 2001 From: Ben Tam Date: Mon, 30 Oct 2023 01:40:09 +0800 Subject: [PATCH] fix: use io.Reader after copy Signed-off-by: Ben Tam --- client.go | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/client.go b/client.go index 42805fc..c9c39b0 100644 --- a/client.go +++ b/client.go @@ -435,10 +435,14 @@ func (c *Client) WriteStream(path string, stream io.Reader, _ os.FileMode) (err return err } } else { - contentLength, err = io.Copy(io.Discard, stream) + buffer := bytes.NewBuffer(make([]byte, 0, 1024 * 1024 /* 1MB */)) + + contentLength, err = io.Copy(buffer, stream) if err != nil { return err } + + stream = buffer } s, err := c.put(path, stream, contentLength)