Bufferize file download (to avoid OOM)
This commit is contained in:
parent
499346e611
commit
992dbfc67d
2 changed files with 25 additions and 20 deletions
|
@ -1,6 +1,7 @@
|
|||
package fic
|
||||
|
||||
import (
|
||||
"bufio"
|
||||
"crypto/sha1"
|
||||
"io"
|
||||
"os"
|
||||
|
@ -11,7 +12,7 @@ import (
|
|||
var FilesDir string
|
||||
|
||||
type EFile struct {
|
||||
Id int64 `json:"id"`
|
||||
Id int64 `json:"id"`
|
||||
origin string
|
||||
Path string `json:"path"`
|
||||
IdExercice int64 `json:"idExercice"`
|
||||
|
@ -51,8 +52,9 @@ func (e Exercice) ImportFile(filePath string, origin string) (EFile, error) {
|
|||
} else {
|
||||
defer fd.Close()
|
||||
|
||||
reader := bufio.NewReader(fd)
|
||||
hash := sha1.New()
|
||||
if _, err := io.Copy(hash, fd); err != nil {
|
||||
if _, err := io.Copy(hash, reader); err != nil {
|
||||
return EFile{}, err
|
||||
}
|
||||
|
||||
|
|
Reference in a new issue