33 lines
597 B
Go
33 lines
597 B
Go
package utils
|
|
|
|
import (
|
|
"bufio"
|
|
"fmt"
|
|
"os"
|
|
)
|
|
|
|
// ReceiveFile Permet de récupérer un fichier sur un reader
|
|
func ReceiveFile(fileName string, fileSize int, reader *bufio.Reader) bool {
|
|
file, fileErr := os.Create(fmt.Sprintf("C:\\Users\\ledou\\Documents\\sbe\\%s", fileName))
|
|
if fileErr != nil {
|
|
return false
|
|
}
|
|
|
|
defer file.Close()
|
|
currentSize := 0
|
|
buffer := make([]byte, 1024)
|
|
|
|
for currentSize < fileSize {
|
|
println("LIS")
|
|
length, err := reader.Read(buffer)
|
|
if err != nil {
|
|
return false
|
|
}
|
|
|
|
currentSize += length
|
|
file.WriteAt(buffer, int64(currentSize))
|
|
}
|
|
|
|
return true
|
|
}
|