openmedialibrary_reader/epub.js/libs/fileStorage.min.js

3 lines
11 KiB
JavaScript
Raw Normal View History

2015-03-07 19:41:19 +00:00
/*! fileStorage - v0.1.0 - 2013-03-28 */var fileStorage = fileStorage || {};
fileStorage.core=fileStorage.core||{},fileStorage.core.dataURLToBlob=function(e){var t=";base64,";if(e.indexOf(t)==-1){var n=e.split(","),r=n[0].split(":")[1],i=n[1];return new Blob([i],{type:r})}var n=e.split(t),r=n[0].split(":")[1],i=window.atob(n[1]),s=i.length,o=new Uint8Array(s);for(var u=0;u<s;++u)o[u]=i.charCodeAt(u);return new Blob([o],{type:r})},fileStorage.core.loadFile=function(e,t,n){var r=new XMLHttpRequest;return this.succeeded=function(e){t&&t(e)},this.failed=function(e){console.log("Error:",e)},this.start=function(){var t=this;r.open("GET",e,!0),r.responseType="blob",r.onload=function(e){this.status==200&&t.succeeded(this.response)},r.onerror=function(e){t.failed(this.status)},r.send()},{start:this.start,succeeded:this.succeeded,failed:this.failed}},fileStorage.Queue=function(e,t){this._q=[],this._tasks={},this.idCount=0,this.concurrency=0,this.workers=[],this.available=[],typeof e=="string"&&(this.workerStr=e,this.addWorkers(t||1)),typeof e=="function"&&(this.workerFunction=e,this.addFakeWorkers(t||1))},fileStorage.Queue.prototype.addWorkers=function(e){var t=this.concurrency,n=t+e;for(var r=t;r<e;r++){var i=new Worker(this.workerStr);this.workers.push(i),this.available.push(r)}this.concurrency=e},fileStorage.Queue.prototype.addFakeWorkers=function(e){var t=this.concurrency,n=t+e;for(var r=t;r<e;r++){var i=new fileStorage.FakeWorker(this.workerFunction);this.workers.push(i),this.available.push(r)}this.concurrency=e},fileStorage.Queue.prototype.add=function(e,t,n){var r=this.idCount;return this._tasks[r]={msg:e,callback:t||function(){}},n?(this._q.unshift(r),this.running||this.run()):this._q.push(r),this.idCount++,r},fileStorage.Queue.prototype.addGroup=function(e,t){var n=this,r=e.length,i=function(){r--,r<=0&&t()};return e.forEach(function(e){n.add(e,i)}),this.running||this.run(),i},fileStorage.Queue.prototype.run=function(e){if(this.running)return;this.running=!0;while(this.available.length){var t=this.next();if(!t)break}},fileStorage.Queue.prototype.find=function(e){},fileStorage.Queue.prototype.next=function(){var e=this,t=this._q.shift(),n,r,i;return typeof t=="undefined"?(this.running=!1,!1):(n=this._tasks[t],r=this.available.pop(),i=this.workers[r],i.postMessage(n.msg),i.onmessage=function(i){var s=i.data;n.callback(s),delete e._tasks[t],e.available.push(r),e.next()},i)},fileStorage.Queue.prototype.empty=function(){this._q=[],this._tasks={}},fileStorage.FakeWorker=function(e){this.func=e},fileStorage.FakeWorker.prototype.postMessage=function(e){setTimeout(function(){this.func(e,this.onmessage)}.bind(this),1)},fileStorage.FakeWorker.prototype.onmessage=function(e){},fileStorage.FakeWorker.prototype.close=function(e){},fileStorage.storage=function(e){return this._supported={},this._storageType=!1,this._store=!1,this.determineStorageMethod(e),this},fileStorage.storage.prototype.storageMethod=function(e){console.log("storageMethod",e),!e||typeof fileStorage.store[e]=="undefined"?this._storageType="none":this._storageType=e,this._store=new fileStorage.store[this._storageType],this._store.failed=this._error},fileStorage.storage.prototype.determineStorageMethod=function(e){var t=["filesystem","indexeddb","websql","ram"],n="none";this.checkSupport();if(e&&(e=="none"||this._supported[e]))n=e;else for(var r=-1,i=t.length;++r<i;)if(this._supported[t[r]]){n=t[r];break}this.storageMethod(n)},fileStorage.storage.prototype.get=function(e,t){return this._store.get(e,t)},fileStorage.storage.prototype.batch=function(e,t){return this._store.batch(e,t)},fileStorage.storage.prototype.getURL=function(e){return this._store.getURL(e)},fileStorage.storage.prototype.save=function(e,t,n){return this._store.save(e,t,n)},fileStorage.storage.prototype._error=function(e){console.log("error",e)},fileStorage.storage.prototype.getStorageType=function(){return this._storageType},fileStorage.storage.prototype.checkSupport=function(){var e="filesystem indexeddb websql ram".split(" "),t="RequestFileSystem IndexedDB openDatabase URL".split(" ");for(var n=-1,r=e.length;++n<r;){var i=e[n],s=t[n];this._supported[i]=this.testSupport(s)}},
//# sourceMappingURL=fileStorage.min.js.map