Created
January 12, 2013 19:10
-
-
Save glynrob/4519988 to your computer and use it in GitHub Desktop.
localStorage test function
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function runStorageTest(){ // fill up all data in local storage to see how much we can squeeze in | |
localStorage.clear(); | |
var i = 0; | |
var testPacket = new Array( 1025 ).join( "a" ); // create 1024 characters so 1KB | |
while (i<maxMBToTest){ // MB level | |
$('#currentDisplay').html(i+'Mb'); | |
var t = 0; | |
while (t<1025){ // KB level | |
try { | |
localStorage.setItem(i+"|"+t, testPacket); | |
} catch( error ) { | |
var kbsaved = Math.floor(((t / 1024) * 100)); // calculate percentage of 1024 | |
storeSpace = i+'.'+kbsaved; // add MB and KB values | |
storeSpace = (Math.floor(storeSpace*100))/100; // rounds down the value | |
t = 1025; | |
i = maxMBToTest+1; | |
} | |
t++; | |
} | |
i++; | |
} | |
$('.message').html('Running test:<br />Space Available = '+storeSpace+'Mb<br /><a id="recheck">Click Here</a> to see your percentage bar of storage'); | |
localStorage.clear(); // clear all local storage | |
localStorage.setItem("storeSpace", storeSpace); // store this value | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment