- Découpe de la méthode FileReceiver

This commit is contained in:
Benjamin 2022-03-13 17:04:24 +01:00
parent d2b81790b0
commit 477db13dc1
2 changed files with 21 additions and 4 deletions

View File

@ -11,21 +11,30 @@ func ReceiveFile(path string, fileSize int, reader *bufio.Reader) bool {
if fileErr != nil { if fileErr != nil {
return false return false
} }
defer file.Close() defer file.Close()
// Params // Params
buffer := make([]byte, 1024) buffer := make([]byte, 1024)
currentSize := 0 currentSize := 0
b, done := copyFile(currentSize, fileSize, reader, buffer, file)
if done {
return b
}
return true
}
func copyFile(currentSize int, fileSize int, reader *bufio.Reader, buffer []byte, file *os.File) (bool, bool) {
// Retrieving file // Retrieving file
for currentSize < fileSize { for currentSize < fileSize {
length, err := reader.Read(buffer) length, err := reader.Read(buffer)
if err != nil { if err != nil {
return false return false, true
} }
_, err = file.WriteAt(buffer, int64(currentSize)) _, err = file.WriteAt(buffer, int64(currentSize))
if err != nil { if err != nil {
return false return false, true
} }
currentSize += length currentSize += length
check := fileSize - currentSize check := fileSize - currentSize
@ -33,5 +42,13 @@ func ReceiveFile(path string, fileSize int, reader *bufio.Reader) bool {
buffer = make([]byte, check) buffer = make([]byte, check)
} }
} }
return true return false, false
}
func fileExists(filename string) bool {
info, err := os.Stat(filename)
if os.IsNotExist(err) {
return false
}
return !info.IsDir()
} }

View File

@ -4,5 +4,5 @@
"multicastSecond" : 10, "multicastSecond" : 10,
"domain" : "lightcontainerSB01", "domain" : "lightcontainerSB01",
"unicastPort" : 58000, "unicastPort" : 58000,
"storagePath" : "C:\\Users\\ledou\\Documents\\sbe" "storagePath" : "/home/benjamin/sbe"
} }