mirror of https://github.com/schollz/croc.git
fix file split bugs and sending server:port display error
This commit is contained in:
parent
33e41b2b0a
commit
407d85270c
|
@ -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"
|
||||
|
||||
|
|
2
relay.go
2
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 {
|
||||
|
|
38
utils.go
38
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
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue