diff --git a/internal/handlers/handlers.go b/internal/handlers/handlers.go index f97f196..059ef41 100644 --- a/internal/handlers/handlers.go +++ b/internal/handlers/handlers.go @@ -136,6 +136,14 @@ func (h *UploadHandlers) Upload(w http.ResponseWriter, r *http.Request) { } defer fDst.Close() + // We initialy set a dst file size to occupy space equal to uploaded's size. + // This is called a sparse file, if you need to know. + // It allows us to have a relatively small buffer size for inotify watcher. + // And it really affects that. I tested it. + fDst.Seek(fHandler.Size-1, io.SeekStart) + fDst.Write([]byte{0}) + fDst.Seek(0, io.SeekStart) + _, err = io.Copy(fDst, f) if err != nil { h.logErr.Println("failed to copy uploaded file to destination:", err)