1"use strict";(self.webpackChunk_N_E=self.webpackChunk_N_E||[]).push([[7112],{7112:(t,e,i)=>{i.r(e),i.d(e,{FilesystemWeb:()=>s});var r=i(8666),a=i(1240);function o(t){let e=t.split("/").filter(t=>"."!==t),i=[];return e.forEach(t=>{".."===t&&i.length>0&&".."!==i[i.length-1]?i.pop():i.push(t)}),i.join("/")}class s extends r.E_{constructor(){super(...arguments),this.DB_VERSION=1,this.DB_NAME="Disc",this._writeCmds=["add","put","delete"],this.downloadFile=async t=>{var e,i;let a,o=(0,r.EA)(t,t.webFetchExtra),s=await fetch(t.url,o);if(t.progress)if(null==s?void 0:s.body){let e=s.body.getReader(),i=0,r=[],o=s.headers.get("content-type"),n=parseInt(s.headers.get("content-length")||"0",10);for(;;){let{done:a,value:o}=await e.read();if(a)break;r.push(o),i+=(null==o?void 0:o.length)||0;let s={url:t.url,bytes:i,contentLength:n};this.notifyListeners("progress",s)}let d=new Uint8Array(i),h=0;for(let t of r)void 0!==t&&(d.set(t,h),h+=t.length);a=new Blob([d.buffer],{type:o||void 0})}else a=new Blob;else a=await s.blob();return{path:(await this.writeFile({path:t.path,directory:null!=(e=t.directory)?e:void 0,recursive:null!=(i=t.recursive)&&i,data:a})).uri,blob:a}}}readFileInChunks(t,e){throw this.unavailable("Method not implemented.")}async initDb(){if(void 0!==this._db)return this._db;if(!("indexedDB"in window))throw this.unavailable("This browser doesn't support IndexedDB");return new Promise((t,e)=>{let i=indexedDB.open(this.DB_NAME,this.DB_VERSION);i.onupgradeneeded=s.doUpgrade,i.onsuccess=()=>{this._db=i.result,t(i.result)},i.onerror=()=>e(i.error),i.onblocked=()=>{console.warn("db blocked")}})}static doUpgrade(t){let e=t.target.result;t.oldVersion,e.objectStoreNames.contains("FileStorage")&&e.deleteObjectStore("FileStorage"),e.createObjectStore("FileStorage",{keyPath:"path"}).createIndex("by_folder","folder")}async dbRequest(t,e){let i=-1!==this._writeCmds.indexOf(t)?"readwrite":"readonly";return this.initDb().then(r=>new Promise((a,o)=>{let s=r.transaction(["FileStorage"],i).objectStore("FileStorage")[t](...e);s.onsuccess=()=>a(s.result),s.onerror=()=>o(s.error)}))}async dbIndexRequest(t,e,i){let r=-1!==this._writeCmds.indexOf(e)?"readwrite":"readonly";return this.initDb().then(a=>new Promise((o,s)=>{let n=a.transaction(["FileStorage"],r).objectStore("FileStorage").index(t)[e](...i);n.onsuccess=()=>o(n.result),n.onerror=()=>s(n.error)}))}getPath(t,e){let i=void 0!==e?e.replace(/^[/]+|[/]+$/g,""):"",r="";return void 0!==t&&(r+="/"+t),""!==e&&(r+="/"+i),r}async clear(){(await this.initDb()).transaction(["FileStorage"],"readwrite").objectStore("FileStorage").clear()}async readFile(t){let e=this.getPath(t.directory,t.path),i=await this.dbRequest("get",[e]);if(void 0===i)throw Error("File does not exist.");return{data:i.content?i.content:""}}async writeFile(t){let e=this.getPath(t.directory,t.path),i=t.data,r=t.encoding,a=t.recursive,o=await this.dbRequest("get",[e]);if(o&&"directory"===o.type)throw Error("The supplied path is a directory.");let s=e.substr(0,e.lastIndexOf("/"));if(void 0===await this.dbRequest("get",[s])){let e=s.indexOf("/",1);if(-1!==e){let i=s.substr(e);await this.mkdir({path:i,directory:t.directory,recursive:a})}}if(!r&&!(i instanceof Blob)&&(i=i.indexOf(",")>=0?i.split(",")[1]:i,!this.isBase64String(i)))throw Error("The supplied data is not valid base64 content.");let n=Date.now(),d={path:e,folder:s,type:"file",size:i instanceof Blob?i.size:i.length,ctime:n,mtime:n,content:i};return await this.dbRequest("put",[d]),{uri:d.path}}async appendFile(t){let e=this.getPath(t.directory,t.path),i=t.data,r=t.encoding,a=e.substr(0,e.lastIndexOf("/")),o=Date.now(),s=o,n=await this.dbRequest("get",[e]);if(n&&"directory"===n.type)throw Error("The supplied path is a directory.");if(void 0===await this.dbRequest("get",[a])){let e=a.indexOf("/",1);if(-1!==e){let i=a.substr(e);await this.mkdir({path:i,directory:t.directory,recursive:!0})}}if(!r&&!this.isBase64String(i))throw Error("The supplied data is not valid base64 content.");if(void 0!==n){if(n.content instanceof Blob)throw Error("The occupied entry contains a Blob object which cannot be appended to.");i=void 0===n.content||r?n.content+i:btoa(atob(n.content)+atob(i)),s=n.ctime}let d={path:e,folder:a,type:"file",size:i.length,ctime:s,mtime:o,content:i};await this.dbRequest("put",[d])}async deleteFile(t){let e=this.getPath(t.directory,t.path);if(void 0===await this.dbRequest("get",[e]))throw Error("File does not exist.");if(0!==(await this.dbIndexRequest("by_folder","getAllKeys",[IDBKeyRange.only(e)])).length)throw Error("Folder is not empty.");await this.dbRequest("delete",[e])}async mkdir(t){let e=this.getPath(t.directory,t.path),i=t.recursive,r=e.substr(0,e.lastIndexOf("/")),a=(e.match(/\//g)||[]).length,o=await this.dbRequest("get",[r]),s=await this.dbRequest("get",[e]);if(1===a)throw Error("Cannot create Root directory");if(void 0!==s)throw Error("Current directory does already exist.");if(!i&&2!==a&&void 0===o)throw Error("Parent directory must exist");if(i&&2!==a&&void 0===o){let e=r.substr(r.indexOf("/",1));await this.mkdir({path:e,directory:t.directory,recursive:i})}let n=Date.now();await this.dbRequest("put",[{path:e,folder:r,type:"directory",size:0,ctime:n,mtime:n}])}async rmdir(t){let{path:e,directory:i,recursive:r}=t,a=this.getPath(i,e),o=await this.dbRequest("get",[a]);if(void 0===o)throw Error("Folder does not exist.");if("directory"!==o.type)throw Error("Requested path is not a directory");let s=await this.readdir({path:e,directory:i});if(0!==s.files.length&&!r)throw Error("Folder is not empty");for(let t of s.files){let a=`${e}/${t.name}`;"file"===(await this.stat({path:a,directory:i})).type?await this.deleteFile({path:a,directory:i}):await this.rmdir({path:a,directory:i,recursive:r})}await this.dbRequest("delete",[a])}async readdir(t){let e=this.getPath(t.directory,t.path),i=await this.dbRequest("get",[e]);if(""!==t.path&&void 0===i)throw Error("Folder does not exist.");let r=await this.dbIndexRequest("by_folder","getAllKeys",[IDBKeyRange.only(e)]);return{files:await Promise.all(r.map(async t=>{let i=await this.dbRequest("get",[t]);return void 0===i&&(i=await this.dbRequest("get",[t+"/"])),{name:t.substring(e.length+1),type:i.type,size:i.size,ctime:i.ctime,mtime:i.mtime,uri:i.path}}))}}async getUri(t){let e=this.getPath(t.directory,t.path),i=await this.dbRequest("get",[e]);return void 0===i&&(i=await this.dbRequest("get",[e+"/"])),{uri:(null==i?void 0:i.path)||e}}async stat(t){let e=this.getPath(t.directory,t.path),i=await this.dbRequest("get",[e]);if(void 0===i&&(i=await this.dbRequest("get",[e+"/"])),void 0===i)throw Error("Entry does not exist.");return{name:i.path.substring(e.length+1),type:i.type,size:i.size,ctime:i.ctime,mtime:i.mtime,uri:i.path}}async rename(t){await this._copy(t,!0)}async copy(t){return this._copy(t,!1)}async requestPermissions(){return{publicStorage:"granted"}}async checkPermissions(){return{publicStorage:"granted"}}async _copy(t,e=!1){let i,{toDirectory:r}=t,{to:s,from:n,directory:d}=t;if(!s||!n)throw Error("Both to and from must be provided");r||(r=d);let h=this.getPath(d,n),l=this.getPath(r,s);if(h===l)return{uri:l};if(function(t,e){t=o(t),e=o(e);let i=t.split("/"),r=e.split("/");return t!==e&&i.every((t,e)=>t===r[e])}(h,l))throw Error("To path cannot contain the from path");try{i=await this.stat({path:s,directory:r})}catch(i){let t=s.split("/");t.pop();let e=t.join("/");if(t.length>0&&"directory"!==(await this.stat({path:e,directory:r})).type)throw Error("Parent directory of the to path is a file")}
1if(i&&"directory"===i.type)throw Error("Cannot overwrite a directory with a file");let c=await this.stat({path:n,directory:d}),u=async(t,e,i)=>{let a=this.getPath(r,t),o=await this.dbRequest("get",[a]);o.ctime=e,o.mtime=i,await this.dbRequest("put",[o])},p=c.ctime?c.ctime:Date.now();switch(c.type){case"file":{let t,i=await this.readFile({path:n,directory:d});e&&await this.deleteFile({path:n,directory:d}),i.data instanceof Blob||this.isBase64String(i.data)||(t=a.Wi.UTF8);let o=await this.writeFile({path:s,directory:r,data:i.data,encoding:t});return e&&await u(s,p,c.mtime),o}case"directory":if(i)throw Error("Cannot move a directory over an existing object");try{await this.mkdir({path:s,directory:r,recursive:!1}),e&&await u(s,p,c.mtime)}catch(t){}for(let t of(await this.readdir({path:n,directory:d})).files)await this._copy({from:`${n}/${t.name}`,to:`${s}/${t.name}`,directory:d,toDirectory:r},e);e&&await this.rmdir({path:n,directory:d})}return{uri:l}}isBase64String(t){try{return btoa(atob(t))==t}catch(t){return!1}}}s._debug=!0}}]);
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.