Download Utils


It continues after a domain reload or an Editor restart. ... Your item code only does the work. ... File locks ... Generic: no assumptions about the host, the file format or the caller.


by Doji Technologies


Price History +

Download Utils downloads large files in Unity reliably, in the Editor and in players. A download continues where it stopped after a network failure, a domain reload or an Editor restart, and it never leaves a broken file that looks complete.


Why this exists

UnityWebRequest with a DownloadHandlerFile is fine for a 5 MB file. For a 4 GB model it is not enough:

  • A dropped connection loses everything received so far. The next attempt starts at byte 0.
  • In the Editor, a domain reload (a script recompile, entering Play mode) stops every running async method. A long download stops halfway, without an error.
  • The file is written at the target path while it downloads. A failed or cancelled download can leave a truncated file that the next run treats as complete.
  • Two Editors, or two packages, that download into the same cache file overwrite each other.
  • Resume logic, server validation, size checks, file locks and persistent state are a few hundred lines of code that is easy to get subtly wrong. Download Utils is that code, with tests.


Resumable downloads

  • Writes to <target>.downloading and continues with HTTP Range requests.
  • Resumes only when it can prove that the bytes on disk belong to the same file: same URL, and the server’s ETag or Last-Modified value sent back with If-Range. If the file on the server changed, it starts over in the same request.
  • Handles servers that ignore Range, reject the range (416) or report another size: it starts over once instead of corrupting the file.


The target file changes only when the download is complete

  • The target is replaced only after the received size matches the size from the server and your optional expected size.
  • A wrong expected size fails as soon as the response headers arrive, before the body downloads.
  • Error responses are never written to the file.


Persistent Editor operations

  • A queue of work saved on disk. It continues after a domain reload or an Editor restart.
  • An entry in the Background Tasks window, with progress and a cancel button.
  • Your item code only does the work. It never saves or resumes state itself.


File locks

  • FileLock.AcquireAsync keeps two downloads of the same file apart, in one Editor or in two. It waits without blocking the main thread.


A small API

  • One method downloads one URL to one file: ResumableDownloader.DownloadFileAsync.
  • Progress in bytes, reported at most every 100 ms. Cancellation with a CancellationToken; the partial file stays for the next call.
  • Errors name the URL and the cause (WebRequestException with the response code).
  • Generic: no assumptions about the host, the file format or the caller. You own the URLs, the cache layout and the validation.
  • The download core is runtime-safe. Only the Editor integration (Background Tasks, the Editor update loop) is in the Editor assembly.
  • Full C# source.


What it does not do

  • No content hash check. If you have a hash, check the file after the download.
  • No archive unpacking, no authentication flows, no parallel chunked downloads of one file.


Requirements

  • Unity 6000.3 LTS or later.


Documentation | GitHub