-
Notifications
You must be signed in to change notification settings - Fork 793
/
Copy pathfiler.min.js
23 lines (22 loc) · 9.02 KB
/
filer.min.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
/*! (c) 2016 Copyright (c) 2016 Eric Bidelman. All rights reserved.
* @version v0.4.5 (Apache) */
var $jscomp={scope:{}};$jscomp.defineProperty="function"==typeof Object.defineProperties?Object.defineProperty:function(a,c,b){if(b.get||b.set)throw new TypeError("ES3 does not support getters and setters.");a!=Array.prototype&&a!=Object.prototype&&(a[c]=b.value)};$jscomp.getGlobal=function(a){return"undefined"!=typeof window&&window===a?a:"undefined"!=typeof global?global:a};$jscomp.global=$jscomp.getGlobal(this);$jscomp.SYMBOL_PREFIX="jscomp_symbol_";
$jscomp.initSymbol=function(){$jscomp.initSymbol=function(){};$jscomp.global.Symbol||($jscomp.global.Symbol=$jscomp.Symbol)};$jscomp.symbolCounter_=0;$jscomp.Symbol=function(a){return $jscomp.SYMBOL_PREFIX+(a||"")+$jscomp.symbolCounter_++};
$jscomp.initSymbolIterator=function(){$jscomp.initSymbol();var a=$jscomp.global.Symbol.iterator;a||(a=$jscomp.global.Symbol.iterator=$jscomp.global.Symbol("iterator"));"function"!=typeof Array.prototype[a]&&$jscomp.defineProperty(Array.prototype,a,{configurable:!0,writable:!0,value:function(){return $jscomp.arrayIterator(this)}});$jscomp.initSymbolIterator=function(){}};$jscomp.arrayIterator=function(a){var c=0;return $jscomp.iteratorPrototype(function(){return c<a.length?{done:!1,value:a[c++]}:{done:!0}})};
$jscomp.iteratorPrototype=function(a){$jscomp.initSymbolIterator();a={next:a};a[$jscomp.global.Symbol.iterator]=function(){return this};return a};$jscomp.array=$jscomp.array||{};$jscomp.iteratorFromArray=function(a,c){$jscomp.initSymbolIterator();a instanceof String&&(a+="");var b=0,d={next:function(){if(b<a.length){var f=b++;return{value:c(f,a[f]),done:!1}}d.next=function(){return{done:!0,value:void 0}};return d.next()}};d[Symbol.iterator]=function(){return d};return d};
$jscomp.polyfill=function(a,c,b,d){if(c){b=$jscomp.global;a=a.split(".");for(d=0;d<a.length-1;d++){var f=a[d];f in b||(b[f]={});b=b[f]}a=a[a.length-1];d=b[a];c=c(d);c!=d&&null!=c&&$jscomp.defineProperty(b,a,{configurable:!0,writable:!0,value:c})}};$jscomp.polyfill("Array.prototype.keys",function(a){return a?a:function(){return $jscomp.iteratorFromArray(this,function(a){return a})}},"es6-impl","es3");self.URL=self.URL||self.webkitURL;self.requestFileSystem=self.requestFileSystem||self.webkitRequestFileSystem;
self.resolveLocalFileSystemURL=self.resolveLocalFileSystemURL||self.webkitResolveLocalFileSystemURL;navigator.temporaryStorage=navigator.temporaryStorage||navigator.webkitTemporaryStorage;navigator.persistentStorage=navigator.persistentStorage||navigator.webkitPersistentStorage;self.BlobBuilder=self.BlobBuilder||self.MozBlobBuilder||self.WebKitBlobBuilder;if(void 0===self.FileError){var FileError=function(){};FileError.prototype.prototype=Error.prototype}
var Util={toArray:function(a){return Array.prototype.slice.call(a||[],0)},strToDataURL:function(a,c,b){return(void 0!=b?b:1)?"data:"+c+";base64,"+self.btoa(a):"data:"+c+","+a},strToObjectURL:function(a,c){for(var b=new Uint8Array(a.length),d=0;d<b.length;++d)b[d]=a.charCodeAt(d);a=new Blob([b],c?{type:c}:{});return self.URL.createObjectURL(a)},fileToObjectURL:function(a){return self.URL.createObjectURL(a)},fileToArrayBuffer:function(a,c,b){var d=new FileReader;d.onload=function(a){c(a.target.result)};
d.onerror=function(a){b&&b(a)};d.readAsArrayBuffer(a)},dataURLToBlob:function(a){if(-1==a.indexOf(";base64,")){var c=a.split(",");a=c[0].split(":")[1];c=decodeURIComponent(c[1]);return new Blob([c],{type:a})}c=a.split(";base64,");a=c[0].split(":")[1];for(var c=window.atob(c[1]),b=c.length,d=new Uint8Array(b),f=0;f<b;++f)d[f]=c.charCodeAt(f);return new Blob([d],{type:a})},arrayBufferToBlob:function(a,c){a=new Uint8Array(a);return new Blob([a],c?{type:c}:{})},arrayBufferToBinaryString:function(a,c,
b){var d=new FileReader;d.onload=function(a){c(a.target.result)};d.onerror=function(a){b&&b(a)};a=new Uint8Array(a);d.readAsBinaryString(new Blob([a]))},arrayToBinaryString:function(a){if("object"!=typeof a)return null;for(var c=a.length,b=Array(c);c--;)b[c]=String.fromCharCode(a[c]);return b.join("")},getFileExtension:function(a){var c=a.lastIndexOf(".");return-1!=c?a.substring(c):""}},MyFileError=function(a){this.prototype=FileError.prototype;this.code=a.code;this.name=a.name};
FileError.BROWSER_NOT_SUPPORTED=1E3;FileError.prototype.__defineGetter__("name",function(){for(var a=Object.keys(FileError),c=0,b;b=a[c];++c)if(FileError[b]==this.code)return b;return"Unknown Error"});
var Filer=new function(){function a(a){if(c=a||null)b=c.root,d=!0}var c=null,b=null,d=!1,f=function(a){0!=a.indexOf("filesystem:")&&(a="/"==a[0]?c.root.toURL()+a.substring(1):0==a.indexOf("./")||0==a.indexOf("../")?"../"==a&&b!=c.root?b.toURL()+"/"+a:b.toURL()+a:b.toURL()+"/"+a);return a},m=function(a,c){var b=arguments[1],e=arguments[2],h=function(a){if(a.code==FileError.NOT_FOUND_ERR){if(e)throw Error('"'+b+'" or "'+e+'" does not exist.');throw Error('"'+b+'" does not exist.');}throw Error("Problem getting Entry for one or more paths.");
},d=f(b);if(3==arguments.length){var q=f(e);self.resolveLocalFileSystemURL(d,function(c){self.resolveLocalFileSystemURL(q,function(b){a(c,b)},h)},h)}else self.resolveLocalFileSystemURL(d,a,h)},p=function(a,b,d,g,l,n){if(!c)throw Error("Filesystem has not been initialized.");if(typeof a!=typeof b)throw Error("These method arguments are not supported.");var e=d||null,h=void 0!=n?n:!1;(a.isFile||b.isDirectory)&&b.isDirectory?h?a.moveTo(b,e,g,l):a.copyTo(b,e,g,l):m(function(a,b){if(b.isDirectory)h?a.moveTo(b,
e,g,l):a.copyTo(b,e,g,l);else if(a=Error('Oops! "'+b.name+" is not a directory!"),l)l(a);else throw a;},a,b)};a.DEFAULT_FS_SIZE=1048576;a.version="0.4.3";a.prototype={get fs(){return c},get isOpen(){return d},get cwd(){return b}};a.prototype.pathToFilesystemURL=function(a){return f(a)};a.prototype.init=function(a,h,k){if(!self.requestFileSystem)throw new MyFileError({code:FileError.BROWSER_NOT_SUPPORTED,name:"BROWSER_NOT_SUPPORTED"});a=a?a:{};var e=a.size||1048576;this.type=self.TEMPORARY;"persistent"in
a&&a.persistent&&(this.type=self.PERSISTENT);var l=function(a){this.size=e;c=a;b=c.root;d=!0;h&&h(a)};this.type==self.PERSISTENT&&navigator.persistentStorage?navigator.persistentStorage.requestQuota(e,function(a){self.requestFileSystem(this.type,a,l.bind(this),k)}.bind(this),k):self.requestFileSystem(this.type,e,l.bind(this),k)};a.prototype.ls=function(a,h,d){if(!c)throw Error("Filesystem has not been initialized.");var e=function(a){b=a;var c=[],e=b.createReader(),g=function(){e.readEntries(function(a){a.length?
(c=c.concat(Util.toArray(a)),g()):(c.sort(function(a,b){return a.name<b.name?-1:b.name<a.name?1:0}),h(c))},d)};g()};a.isDirectory?e(a):0==a.indexOf("filesystem:")?m(e,a):b.getDirectory(a,{},e,d)};a.prototype.mkdir=function(a,h,d,g){if(!c)throw Error("Filesystem has not been initialized.");var e=null!=h?h:!1,k=a.split("/"),f=function(b,c){if("."==c[0]||""==c[0])c=c.slice(1);b.getDirectory(c[0],{create:!0,exclusive:e},function(b){if(b.isDirectory)c.length&&1!=k.length?f(b,c.slice(1)):d&&d(b);else if(b=
Error(a+" is not a directory"),g)g(b);else throw b;},function(b){if(b.code==FileError.INVALID_MODIFICATION_ERR)if(b.message="'"+a+"' already exists",g)g(b);else throw b;})};f(b,k)};a.prototype.open=function(a,b,d){if(!c)throw Error("Filesystem has not been initialized.");a.isFile?a.file(b,d):m(function(a){a.file(b,d)},f(a))};a.prototype.create=function(a,d,k,g){if(!c)throw Error("Filesystem has not been initialized.");b.getFile(a,{create:!0,exclusive:null!=d?d:!0},k,function(b){b.code==FileError.INVALID_MODIFICATION_ERR&&
(b.message="'"+a+"' already exists");if(g)g(b);else throw b;})};a.prototype.mv=function(a,b,c,d,l){p.bind(this,a,b,c,d,l,!0)()};a.prototype.rm=function(a,b,d){if(!c)throw Error("Filesystem has not been initialized.");var e=function(a){a.isFile?a.remove(b,d):a.isDirectory&&a.removeRecursively(b,d)};a.isFile||a.isDirectory?e(a):m(e,a)};a.prototype.cd=function(a,d,k){if(!c)throw Error("Filesystem has not been initialized.");a.isDirectory?(b=a,d&&d(b)):(a=f(a),m(function(a){if(a.isDirectory)b=a,d&&d(b);
else if(a=Error("Path was not a directory."),k)k(a);else throw a;},a))};a.prototype.cp=function(a,b,c,d,f){p.bind(this,a,b,c,d,f)()};a.prototype.write=function(a,d,f,g){if(!c)throw Error("Filesystem has not been initialized.");var e=function(a){a.createWriter(function(b){b.onerror=g;if(d.append)b.onwriteend=function(b){f&&f(a,this)},b.seek(b.length);else{var c=!1;b.onwriteend=function(b){c?f&&f(a,this):(c=!0,this.truncate(this.position))}}d.data.__proto__==ArrayBuffer.prototype&&(d.data=new Uint8Array(d.data));
var e=new Blob([d.data],d.type?{type:d.type}:{});b.write(e)},g)};a.isFile?e(a):0==a.indexOf("filesystem:")?m(e,a):b.getFile(a,{create:!0,exclusive:!1},e,g)};a.prototype.df=function(a,b){var c=function(b,c){a(b,c-b,c)};if(!navigator.temporaryStorage.queryUsageAndQuota||!navigator.persistentStorage.queryUsageAndQuota)throw Error("Not implemented.");self.TEMPORARY==this.type?navigator.temporaryStorage.queryUsageAndQuota(c,b):self.PERSISTENT==this.type&&navigator.persistentStorage.queryUsageAndQuota(c,
b)};return a};"undefined"!==typeof exports&&("undefined"!==typeof module&&module.exports&&(module.exports=Filer),exports.Filer=Filer);