To download big files correctly (especially on mobile devices) we should try to achieve the following goals:
Separate the download process from the current view in a background task: we don´t want the download to stop if we navigate to another view or the device goes idle
The download stream should not write directly to memory: the device may run out of memory very soon, crashing your app. Instead, we should write to the file system directly as soon as the bytes are downloaded.
Report progress: users should know how long it will take to finish. Otherwise it may look like it´s stuck
The same rules apply to any operating system, like iOS and Android (that will come in a future post).
It turns out that doing all this on Windows RT is fairly easy thanks to the class Windows.Networking.BackgroundTransfer.BackgroundDownloader, because it will follow all those rules:
That´s it actually, but in order to implement this in a cross-platform way (thinking about iOS and Android and Xamarin.Forms) I created and event OnDownloadPercentProgress and wrapped it all with an interface that is platform agnostic:
IFolder comes from the cross-platform storage library called PCLStorage