HTTP- Mozilla 2 . , , , - . , 100% - , , , . , Mozilla , API. , , .
. , , , , . , URI , . , .
, HTTP- , , , , . , , (, ) , . , ALWAYS , . , , ( - + - Mozilla) .
URI , , . . - nsICacheEntryOpenCallback. , . -: onCacheEntryCheck (, appcache) onCacheEntryAvilable (, isnew, appcache, ).
:
var cacheWaiter = {
onCacheEntryCheck: function( descriptor, appcache )
{
try{
if( descriptor.dataSize < descriptor.predictedDataSize )
return Components.interfaces.nsICacheEntryOpenCallback.RECHECK_AFTER_WRITE_FINISHED;
}
catch(e){
return Components.interfaces.nsICacheEntryOpenCallback.RECHECK_AFTER_WRITE_FINISHED;
}
return Components.interfaces.nsICacheEntryOpenCallback.ENTRY_WANTED;
}
onCacheEntryAvailable: function( descriptor, isnew, appcache, status )
{
var cacheentryinputstream = descriptor.openInputStream(0);
var blobarray = new Array(0);
var buffer = new Array(1024);
for( var i = descriptor.dataSize; i > 0; i -= 1024)
{
try{
cacheentryinputstream.read( buffer, 1024 );
}
catch(e){
i += 1024;
}
for( var j = 0; j < 1024; j++ )
{
blobarray.push(buffer.charAt(j));
}
}
}
var theblob = new Blob(blobarray);
}
, , . - :
var theuri = "http://www.example.com/image.jpg";
var cacheservice = Components.classes["@mozilla.org/netwerk/cache-storage-service;1"].getService(Components.interfaces.nsICacheStorageService);
var {LoadContextInfo} = Components.utils.import("resource://gre/modules/LoadContextInfo.jsm",{})
var hdcache = cacheservice.diskCacheStorage(LoadContextInfo.default, true);
hdcache.asyncOpenURI(ioservice.newURI(theuri, null, null), "", hdcache.OPEN_NORMALLY, cacheWaiter);
URI, , URL- . AJAX ( , - , ). URL-, . , .
, , !