Merge pull request #623 from justfalter/read-full

perf: ensure full write buffer for *File.ReadFrom
diff --git a/client.go b/client.go
index a5a915a..0d4d9a9 100644
--- a/client.go
+++ b/client.go
@@ -1842,7 +1842,8 @@
 		off := f.offset
 
 		for {
-			n, err := r.Read(b)
+			// Fill the entire buffer.
+			n, err := io.ReadFull(r, b)
 
 			if n > 0 {
 				read += int64(n)
@@ -1868,7 +1869,7 @@
 			}
 
 			if err != nil {
-				if err != io.EOF {
+				if !errors.Is(err, io.EOF) && !errors.Is(err, io.ErrUnexpectedEOF) {
 					errCh <- rwErr{off, err}
 				}
 				return
@@ -2022,7 +2023,8 @@
 
 	var read int64
 	for {
-		n, err := r.Read(b)
+		// Fill the entire buffer.
+		n, err := io.ReadFull(r, b)
 		if n < 0 {
 			panic("sftp.File: reader returned negative count from Read")
 		}
@@ -2039,7 +2041,7 @@
 		}
 
 		if err != nil {
-			if err == io.EOF {
+			if errors.Is(err, io.EOF) || errors.Is(err, io.ErrUnexpectedEOF) {
 				return read, nil // return nil explicitly.
 			}