Filesaver.js: How to know when the download begins and ends

Created on 10 Jun 2019  路  3Comments  路  Source: eligrey/FileSaver.js

hi, I want to make an animation, so when the download begins the animation too, and the download ends and also the animation, but the function saveAs() is not a promise and returns void(or undefined), so, the only way to know if the download is ready is when the file explorer appears.

how I can know when the download begins and ends??
I'm just downloading images

Most helpful comment

You know, we can pass a url to saveAs. In that case, we might need a promise as return value.

All 3 comments

It's impossible to figure out with FileSaver.
Saving a blob is pretty much instant. and you have no way of knowing if the user even started the download

However StreamSaver have some degree of figuring out different state of the download progress based on stream. it's not elegant but you can figure out if the stream was canceled. if the stream was back pressured (writing to much/to fast) no decrease === user paused the download. if user ask for more data that should be written and when the stream is ended

Here is an example where desiredSize is lowered as you pause the download (only works with transferable stream)

You know, we can pass a url to saveAs. In that case, we might need a promise as return value.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

CSchulz picture CSchulz  路  4Comments

sangyeol-kim picture sangyeol-kim  路  5Comments

danielbronder picture danielbronder  路  6Comments

HeroSony picture HeroSony  路  5Comments

mluis picture mluis  路  3Comments