home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Chip 2011 November
/
CHIP_2011_11.iso
/
Programy
/
Narzedzia
/
AIMP2
/
aimp_2.61.583.exe
/
$TEMP
/
YandexPackSetup.msi
/
filC5FBE547B3B4874572A8DCB7B5CEC060
< prev
next >
Wrap
Text File
|
2010-07-12
|
2KB
|
82 lines
var G_CacheWrapper = {
_clientID: "YandexCacheWrapper",
_expirationTime: 55,
_cacheSession: null,
get cacheSession() {
if (!this._cacheSession) {
const CACHE_SERVICE = Cc["@mozilla.org/network/cache-service;1"].getService(Ci.nsICacheService);
this._cacheSession = CACHE_SERVICE.createSession(this._clientID, Ci.nsICache.STORE_ANYWHERE, true);
this._cacheSession.doomEntriesIfExpired = true;
}
return this._cacheSession;
},
_openCacheEntry: function(aKey, aAccess) {
try {
if (this.cacheSession)
return this.cacheSession.openCacheEntry(aKey, aAccess, true);
} catch(e) {}
return null;
},
_doomEntry: function(aKey) {
var entry = this._openCacheEntry(aKey, Ci.nsICache.ACCESS_WRITE);
if (entry) {
entry.doom();
entry.close();
}
},
writeData: function(aKey, aData) {
var result = false;
this._doomEntry(aKey);
if (aData) {
var entry = this._openCacheEntry(aKey, Ci.nsICache.ACCESS_READ_WRITE);
if (entry && entry.accessGranted == Ci.nsICache.ACCESS_WRITE) {
var data = UConverter.ConvertFromUnicode(aData);
var entryOutputStream = entry.openOutputStream(0);
entryOutputStream.write(data, data.length);
entryOutputStream.close();
entry.setExpirationTime(parseInt(Date.now() / 1000, 10) + this._expirationTime);
entry.markValid();
result = true;
}
entry.close();
}
return result;
},
readData: function(aKey) {
var result = null;
var entry = this._openCacheEntry(aKey, Ci.nsICache.ACCESS_READ);
if (entry) {
var entryInputStream = entry.openInputStream(0);
var binaryInputStream = Cc["@mozilla.org/binaryinputstream;1"].createInstance(Ci.nsIBinaryInputStream);
binaryInputStream.setInputStream(entryInputStream);
var data = binaryInputStream.readBytes(binaryInputStream.available());
entryInputStream.close();
binaryInputStream.close();
entry.close();
result = UConverter.ConvertToUnicode(data);
}
return result;
}
}