Changeset 1045

Show
Ignore:
Timestamp:
2008-08-18 03:09:50 (3 months ago)
Author:
MaierMan
Message:

Allow to load the last few bytes of a file first. (backend only)

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/chrome/content/dta/manager.js

    r1044 r1045  
    8484const STREAMS_FREQ = 200; 
    8585 
     86const END_FIRST_SIZE = 2 * 1024 * 1024; 
     87 
    8688let Prompts = {}; 
    8789Components.utils.import('resource://dta/prompts.jsm', Prompts); 
     
    16851687                        download.chunks.push(chunk); 
    16861688                        download.chunks.sort(function(a,b) { return a.start - b.start; }); 
    1687                         downloadChunk(download, chunk, header); 
    1688                         download.sessionConnctions = 0;  
     1689                        downloadChunk(download, chunk, header);  
    16891690                } 
    16901691                function downloadChunk(download, chunk, header) { 
     
    17101711                        if (this.chunks.length == 0) { 
    17111712                                downloadNewChunk(this, 0, 0, true); 
     1713                                this.sessionConnections = 0;                             
    17121714                                return false; 
    17131715                        } 
    1714  
     1716                         
    17151717                        // start some new chunks 
    1716                         var paused = this.chunks.filter( 
    1717                                 function (chunk) { 
    1718                                         return !(chunk.running || chunk.complete); 
    1719                                 } 
    1720                         ); 
     1718                        let paused = this.chunks.filter(function (chunk) !(chunk.running || chunk.complete)); 
     1719                         
    17211720                        while (this.activeChunks < this.maxChunks) { 
    17221721 
     
    17271726                                        continue; 
    17281727                                } 
     1728 
     1729                                if (this.chunks.length == 1 && Prefs.loadEndFirst && this.chunks[0].remainder > 3 * END_FIRST_SIZE) { 
     1730                                        // we should download the end first! 
     1731                                        let c = this.chunks[0]; 
     1732                                        let end = c.end; 
     1733                                        c.end -= END_FIRST_SIZE; 
     1734                                        downloadNewChunk(this, c.end + 1, end);                                  
     1735                                        rv = true; 
     1736                                        continue; 
     1737                                } 
    17291738                                 
    17301739                                // find biggest chunk 
    17311740                                let biggest = null; 
    1732                                 this.chunks.forEach( 
    1733                                         function (chunk) { 
    1734                                                 if (chunk.running && chunk.remainder > MIN_CHUNK_SIZE * 2) { 
    1735                                                         if (!biggest || biggest.remainder < chunk.remainder) { 
    1736                                                                 biggest = chunk; 
    1737                                                         } 
     1741                                for each (let chunk in this.chunks) { 
     1742                                        if (chunk.running && chunk.remainder > MIN_CHUNK_SIZE * 2) { 
     1743                                                if (!biggest || biggest.remainder < chunk.remainder) { 
     1744                                                        biggest = chunk; 
    17381745                                                } 
    17391746                                        } 
    1740                                 ); 
     1747                                } 
    17411748 
    17421749                                // nothing found, break 
     
    17441751                                        break; 
    17451752                                } 
    1746                                 var end = biggest.end; 
    1747                                 var bend = biggest.start + biggest.written + Math.floor(biggest.remainder / 2); 
    1748                                 biggest.end = bend; 
     1753                                let end = biggest.end; 
     1754                                biggest.end = biggest.start + biggest.written + Math.floor(biggest.remainder / 2); 
    17491755                                downloadNewChunk(this, biggest.end + 1, end); 
    17501756                                rv = true; 
  • trunk/chrome/content/dta/manager/prefs.js

    r993 r1045  
    6161                ['confirmRemove', true], 
    6262                ['permissions', 384], 
     63                ['loadEndFirst', false] 
    6364        ], 
    6465 
  • trunk/defaults/preferences/dta.js

    r827 r1045  
    6868pref("extensions.dta.confirmremove", true); 
    6969pref("extensions.dta.permissions", 384); 
     70pref("extensions.dta.loadendfirst", false); 
    7071 
    7172// Seamonkey specific