From 886a478428d9fa8e68301d3c0a93cf41883824fd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Denis=20Nu=C8=9Biu?= Date: Fri, 22 Dec 2017 18:38:24 +0200 Subject: [PATCH] Fix for Getfile --- server/server/commands.go | 19 ++----------------- 1 file changed, 2 insertions(+), 17 deletions(-) diff --git a/server/server/commands.go b/server/server/commands.go index c785619..0894109 100644 --- a/server/server/commands.go +++ b/server/server/commands.go @@ -63,7 +63,7 @@ func SendASCIIPic(c Client, path string) error { // GetFile sends the file to the client and returns true if it succeeds and false otherwise. // it also returns the total number of send bytes. -func GetFile(c Client, path string) (int, error) { +func GetFile(c Client, path string) (int64, error) { fileName, sanitized := sanitizeFilePath(path) if sanitized { return 0, ErrSlashNotAllowed @@ -76,22 +76,7 @@ func GetFile(c Client, path string) (int, error) { } defer file.Close() - var data = make([]byte, DataBufferSize, DataBufferSize) - totalSend := 0 - for { - n, err := file.Read(data) - if err == io.EOF { - break - } else if err != nil { - return totalSend, err - } - - totalSend += n - _, err = c.Connection().Write(data) - if err != nil { - break - } - } + totalSend, err := io.Copy(c.Connection(), file) return totalSend, nil }