0

The Question is in the title: How does the Mega.co.nz download progress-bar work? I know about the filesystem API, but how are the files streamed from the server to the filesystem? How do they get the progress of the download?

  • 1
    @pnuts I am a web-developer and have a customer that want something like that. Mega is the site with the best implementation of this mechanism i know about. I will provide an answer for the question once i solved it. – user2482138 Apr 24 '14 at 9:08
  • 1
    @pnuts Thanks for the effort. I speak about the web-application ;) there is a download-progress-bar which is pretty fallback-save. I implemented a similar feature by using multiple XmlHttpRequest Level 2 (Level 1 fallback), FileParting, Chunking, Html 5 FileSystem (IndexedDB fallback) and BlobBuilder myself now (finished it a few minutes ago). I will post the answer as soon as the code is pretty. Thank you a lot. – user2482138 Apr 25 '14 at 4:18
  • How exactly you want it? MEGA divides files in chunks, so they can get it based on on the number of loaded chunks (check section 12.10 forwards from the developer documentation). Other way is using onprogress, as seen in this question. – Gustavo Rodrigues Apr 13 '15 at 1:01
1

Calculating the % of bytes already downloaded is an easy task once you have in hands the total bytes already download and the total filesize. The file transfer may occur in any method, such as websockets or XMLHttpRequest (Mega uses this last one), but the main point is: it's totally useless to create a file download system exactly like Mega unless you want to keep encrypted files on your server (it's the case of Mega).

Once Mega downloads reaches 99%, it shows "decrypting...". This means that the whole file is sent encrypted. As the decryption key on the URL is after a "#", it suggests that the decryption key is not sent to the server and stays on the client-side.

Mega uses FileSystem API to go storing the encrypted file somewhere on your %APPDATA% (I've heard that they store the encrypted file as blob using browser storage APIs if the browser does not support FileSystem API). Once all the bytes are transferred, the file decryption algorithm runs also on your browser (with Javascript), takes the file content and decrypts it without the need of the server. Finally, it (hiddenly) creates a object URL for the blob and forces your browser to download it (you can achieve it with FileSaver).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.