When clicking the download button for the backup options, the download only starts once the zipfile has been created completely. This results in delayed user feedback which is never pretty, potentially leading to multiple button clicks which will create multiple tempfiles.
Instead of creating a zipfile and writing it to a tempfile, use a pipe. A thread is started which writes the zipped data to the pipe. Flasks send_file will read the data from the pipe so the download can instantly start while the zipfile is being created.
The new approach also means that using the backup function no longer causes any sd-card wear.
When clicking the download button for the backup options, the download only starts once the zipfile has been created completely. This results in delayed user feedback which is never pretty, potentially leading to multiple button clicks which will create multiple tempfiles.
Instead of creating a zipfile and writing it to a tempfile, use a pipe. A thread is started which writes the zipped data to the pipe. Flasks send_file will read the data from the pipe so the download can instantly start while the zipfile is being created.
The new approach also means that using the backup function no longer causes any sd-card wear.