Récupération d'un fichier avec BUFFER. DOnc plus optimisé
This commit is contained in:
parent
6fa5f6c1c4
commit
b198f51c1e
@ -3,7 +3,6 @@ package utils
|
||||
import (
|
||||
"bufio"
|
||||
"fmt"
|
||||
"io"
|
||||
"os"
|
||||
)
|
||||
|
||||
@ -14,12 +13,19 @@ func ReceiveFile(fileName string, fileSize int, reader *bufio.Reader) bool {
|
||||
return false
|
||||
}
|
||||
|
||||
println(1)
|
||||
defer file.Close()
|
||||
_, err := io.CopyN(file, reader, int64(fileSize))
|
||||
println(2)
|
||||
currentSize := 0
|
||||
buffer := make([]byte, 1024)
|
||||
|
||||
for currentSize < fileSize {
|
||||
length, err := reader.Read(buffer)
|
||||
if err != nil {
|
||||
return false
|
||||
}
|
||||
|
||||
currentSize += length
|
||||
file.WriteAt(buffer, int64(currentSize))
|
||||
}
|
||||
|
||||
return true
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user