univ-fs-webnfs
Version:
The universal Filesystem for Web File System Access API (Native File System API)
1 lines • 3.82 kB
JavaScript
(self.webpackChunkuniv_fs_webnfs=self.webpackChunkuniv_fs_webnfs||[]).push([[215],{215:(e,t,r)=>{"use strict";r.r(t),r.d(t,{TextHelper:()=>i}),r(600);var n=r(706);const o=new TextEncoder,f=new TextDecoder;class i{async bufferToText(e,t){const r=t.bufferToTextCharset;return"utf8"===r?f.decode(e):"utf16le"===r?String.fromCharCode.apply(null,Array.from(e)):await this.convert(e,{to:"UNICODE",from:r.toUpperCase(),type:"string"})}async textToBuffer(e,t){const r=t.textToBufferCharset;if("utf8"===r)return o.encode(e);if("utf16le"===r){const t=this.textToUtf16leBuffer(e);return(0,n.ai)(t)}const f=await this.convert(e,{to:r.toUpperCase(),from:"UNICODE",type:"arraybuffer"});return(0,n.ai)(f)}async convert(e,t){if(void 0===this._convert)try{this._convert=(await r.e(977).then(r.t.bind(r,977,23))).convert}catch{this._convert=null}if(!this._convert)throw new Error(`Illegal encoding: from=${t.from}, to=${t.to}`);return this.convert(e,t)}textToUtf16leBuffer(e){const t=new ArrayBuffer(2*e.length),r=new Uint16Array(t);for(let t=0,n=e.length;t<n;t++)r[t]=e.charCodeAt(t);return t}}},600:function(e,t,r){!function(e){"use strict";function t(e){for(var t=0,r=Math.min(65536,e.length+1),n=new Uint16Array(r),o=[],f=0;;){var i=t<e.length;if(!i||f>=r-1){var a=n.subarray(0,f);if(o.push(String.fromCharCode.apply(null,a)),!i)return o.join("");e=e.subarray(t),t=0,f=0}var c=e[t++];if(0==(128&c))n[f++]=c;else if(192==(224&c)){var u=63&e[t++];n[f++]=(31&c)<<6|u}else if(224==(240&c)){u=63&e[t++];var s=63&e[t++];n[f++]=(31&c)<<12|u<<6|s}else if(240==(248&c)){var l=(7&c)<<18|(u=63&e[t++])<<12|(s=63&e[t++])<<6|63&e[t++];l>65535&&(l-=65536,n[f++]=l>>>10&1023|55296,l=56320|1023&l),n[f++]=l}}}var r="Failed to ",n=function(e,t,n){if(e)throw new Error("".concat(r).concat(t,": the '").concat(n,"' option is unsupported."))},o="function"==typeof Buffer&&Buffer.from,f=o?function(e){return Buffer.from(e)}:function(e){for(var t=0,r=e.length,n=0,o=Math.max(32,r+(r>>>1)+7),f=new Uint8Array(o>>>3<<3);t<r;){var i=e.charCodeAt(t++);if(i>=55296&&i<=56319){if(t<r){var a=e.charCodeAt(t);56320==(64512&a)&&(++t,i=((1023&i)<<10)+(1023&a)+65536)}if(i>=55296&&i<=56319)continue}if(n+4>f.length){o+=8,o=(o*=1+t/e.length*2)>>>3<<3;var c=new Uint8Array(o);c.set(f),f=c}if(0!=(4294967168&i)){if(0==(4294965248&i))f[n++]=i>>>6&31|192;else if(0==(4294901760&i))f[n++]=i>>>12&15|224,f[n++]=i>>>6&63|128;else{if(0!=(4292870144&i))continue;f[n++]=i>>>18&7|240,f[n++]=i>>>12&63|128,f[n++]=i>>>6&63|128}f[n++]=63&i|128}else f[n++]=i}return f.slice?f.slice(0,n):f.subarray(0,n)};function i(){this.encoding="utf-8"}i.prototype.encode=function(e,t){return n(t&&t.stream,"encode","stream"),f(e)};var a=!o&&"function"==typeof Blob&&"function"==typeof URL&&"function"==typeof URL.createObjectURL,c=["utf-8","utf8","unicode-1-1-utf-8"],u=t;o?u=function(e,t){return(e instanceof Buffer?e:Buffer.from(e.buffer,e.byteOffset,e.byteLength)).toString(t)}:a&&(u=function(e){try{return function(e){var t;try{var r=new Blob([e],{type:"text/plain;charset=UTF-8"});t=URL.createObjectURL(r);var n=new XMLHttpRequest;return n.open("GET",t,!1),n.send(),n.responseText}finally{t&&URL.revokeObjectURL(t)}}(e)}catch(r){return t(e)}});var s="construct 'TextDecoder'",l="".concat(r," ").concat(s,": the ");function h(e,t){if(n(t&&t.fatal,s,"fatal"),e=e||"utf-8",!(o?Buffer.isEncoding(e):-1!==c.indexOf(e.toLowerCase())))throw new RangeError("".concat(l," encoding label provided ('").concat(e,"') is invalid."));this.encoding=e,this.fatal=!1,this.ignoreBOM=!1}h.prototype.decode=function(e,t){var r;return n(t&&t.stream,"decode","stream"),r=e instanceof Uint8Array?e:e.buffer instanceof ArrayBuffer?new Uint8Array(e.buffer):new Uint8Array(e),u(r,this.encoding)},e.TextEncoder=e.TextEncoder||i,e.TextDecoder=e.TextDecoder||h}("undefined"!=typeof window?window:void 0!==r.g?r.g:this)}}]);