Nikhil Gupta
Nikhil Gupta

Reputation: 881

How to resume downloads of large files in ios

I am using downloadTask of URLSession to download a large file. The problem i am facing is how to provide pause and resume functionality. I have read that cancelling the downloadTask with resumeData gives back resumeData which can be used next time to resume the download. But for a really large file, this resumeData can be very large (i think. depending on file size and at what stage download is paused it can be very large). How do i persist this large resumeData so that i can use it next time to resume download. Also there can be multiple downloads at the same time, which increases the same problem more.

Upvotes: 1

Views: 714

Answers (1)

dgatwood
dgatwood

Reputation: 10407

The resume data blob does not contain the actual received data. If it did, you wouldn't be able to resume downloading a multi-gigabyte file on a 32-bit architecture.

What it contains is a bunch of metadata for the transfer:

  • A URL on disk where the temporary file is stored.
  • A time stamp indicating when the fetch began so it can ask the server if the file has changed since then.
  • The request URL.
  • The set of request headers.
  • Probably some UUIDs.

And it might just be the URL of a metadata file on disk that contains the things listed above. I'm not sure which.

Either way, you will not get a multi-gigabyte resumeData blob. That would be devastating. The whole point of a download task is that it downloads to disk, not to memory.

Upvotes: 4

Related Questions