diff --git a/connect.go b/connect.go index aa98987f..17c0f274 100644 --- a/connect.go +++ b/connect.go @@ -13,7 +13,7 @@ import ( "sync" "time" - humanize "github.com/dustin/go-humanize" + "github.com/dustin/go-humanize" "github.com/schollz/progressbar" "github.com/schollz/tarinator-go" diff --git a/relay.go b/relay.go index 03c6ce4a..80e4a64b 100644 --- a/relay.go +++ b/relay.go @@ -254,7 +254,7 @@ func receiveMessage(connection net.Conn) string { logger.Warn("read deadline, no response") return "" } - return strings.Replace(string(messageByte), ":", "", -1) + return strings.TrimRight(string(messageByte), ":") } func fillString(retunString string, toLength int) string { diff --git a/utils.go b/utils.go index a4d60a81..b4487f1c 100644 --- a/utils.go +++ b/utils.go @@ -49,38 +49,22 @@ func SplitFile(fileName string, numPieces int) (err error) { } bytesPerPiece := int(math.Ceil(float64(fi.Size()) / float64(numPieces))) - bytesRead := 0 - i := 0 - out, err := os.Create(fileName + "." + strconv.Itoa(i)) - if err != nil { - return err - } - buf := make([]byte, 4096) - if bytesPerPiece < 4096/numPieces { - buf = make([]byte, bytesPerPiece) - } - for { + + buf := make([]byte, bytesPerPiece) + for i := 0; i < numPieces; i++ { + + out, err := os.Create(fileName + "." + strconv.Itoa(i)) + if err != nil { + return err + } n, err := file.Read(buf) out.Write(buf[:n]) - // If written bytes count is smaller than lenght of buffer - // then we don't create one more empty file - if err == io.EOF || n < len(buf) { + out.Close() + + if err == io.EOF { break } - bytesRead += n - - if bytesRead >= bytesPerPiece { - // Close file and open a new one - out.Close() - i++ - out, err = os.Create(fileName + "." + strconv.Itoa(i)) - if err != nil { - return err - } - bytesRead = 0 - } } - out.Close() return nil }