- Découpe de la méthode FileReceiver
This commit is contained in:
parent
d2b81790b0
commit
477db13dc1
@ -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()
|
||||||
}
|
}
|
||||||
|
@ -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"
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user