UNPKG

fa-toolkit

Version:

a devtool for fast app

1 lines 6.83 kB
"use strict";var _0x3efa78=_0xbd42;function _typeof(e){var r=_0xbd42;return(_typeof="function"==typeof Symbol&&r(558)==typeof Symbol[r(500)]?function(e){return typeof e}:function(e){var t=r;return e&&t(484)==typeof Symbol&&e[t(556)]===Symbol&&e!==Symbol[t(506)]?t(558):typeof e})(e)}function _toConsumableArray(e){return _arrayWithoutHoles(e)||_iterableToArray(e)||_unsupportedIterableToArray(e)||_nonIterableSpread()}function _nonIterableSpread(){throw new TypeError(_0xbd42(488))}function _0x3a7c(){var e=["Object","missingZip","72346tfqnrY","extractAllTo Failed.","message","checkFileValid","unlinkZip","object","fileNameInvalidReg","The number of files in the .zip file is too large.","577555hICfuf","getEntries","callback","concat","8784mNDbxL","getData","Invalid unzip parameter.","aboveFileAmount","configurable","toString","checkFilesAmount","unlinkSync","overwrite","aboveFileSize","toPrimitive","existsSync","success","writable","adm-zip","maxFilesAmount","constructor","zip","symbol","277728uMqZfQ","slice","name","byteLength","callbackArgs","zipPath","function","Map","Set","checkZipExists","Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.","defineProperty","test","setCallback","entryName","checkZipValid","4LQlGnt","number","string","call","4189080McXFuD","path","iterator","value","The .zip file is invalid.","length","Arguments","join","prototype","The file name in the .zip file is invalid.","The file in the .zip file is too large.","checkResult","undefined","maxFileSize","72810WdqiWD","3983fRMzep","boolean","setCheckResult","187251EjtFBz","Cannot call a class as a function","checkDone","The .zip file does not exist.","key","invalidParams","assign","extractAllTo","2320BhrnLl","@@iterator"];return(_0x3a7c=function(){return e})()}function _unsupportedIterableToArray(e,t){var r=_0xbd42;if(e){if(typeof e===r(496))return _arrayLikeToArray(e,t);var i=Object[r(506)][r(545)].call(e)[r(479)](8,-1);return(i=i===r(526)&&e[r(556)]?e[r(556)][r(480)]:i)===r(485)||i===r(486)?Array.from(e):i===r(504)||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/[r(490)](i)?_arrayLikeToArray(e,t):void 0}}function _iterableToArray(e){var t=_0xbd42;if(typeof Symbol!==t(510)&&null!=e[Symbol[t(500)]]||null!=e[t(525)])return Array.from(e)}function _arrayWithoutHoles(e){if(Array.isArray(e))return _arrayLikeToArray(e)}function _arrayLikeToArray(e,t){(null==t||t>e[_0xbd42(503)])&&(t=e.length);for(var r=0,i=new Array(t);r<t;r++)i[r]=e[r];return i}function _classCallCheck(e,t){if(!(e instanceof t))throw new TypeError(_0xbd42(517))}function _defineProperties(e,t){for(var r=_0xbd42,i=0;i<t.length;i++){var a=t[i];a.enumerable=a.enumerable||!1,a[r(544)]=!0,r(501)in a&&(a[r(553)]=!0),Object[r(489)](e,_toPropertyKey(a[r(520)]),a)}}function _createClass(e,t,r){var i=_0xbd42;return t&&_defineProperties(e.prototype,t),r&&_defineProperties(e,r),Object[i(489)](e,"prototype",{writable:!1}),e}function _0xbd42(e,t){var r=_0x3a7c();return(_0xbd42=function(e,t){return r[e-=479]})(e,t)}function _toPropertyKey(e){var t=_0xbd42,e=_toPrimitive(e,t(496));return _typeof(e)===t(558)?e:String(e)}function _toPrimitive(e,t){var r=_0xbd42;if(_typeof(e)!==r(533)||null===e)return e;var i=e[Symbol[r(550)]];if(void 0===i)return("string"===t?String:Number)(e);t=i[r(497)](e,t||"default");if("object"!==_typeof(t))return t;throw new TypeError("@@toPrimitive must return a primitive value.")}!function(){for(var e=_0xbd42,t=_0x3a7c();;)try{if(432467==+parseInt(e(536))+-parseInt(e(528))/2+parseInt(e(516))/3+parseInt(e(494))/4*(parseInt(e(498))/5)+-parseInt(e(540))/6*(-parseInt(e(513))/7)+parseInt(e(559))/8+parseInt(e(512))/9*(-parseInt(e(524))/10))break;t.push(t.shift())}catch(e){t.push(t.shift())}}();var AdmZip=require(_0x3efa78(554)),fs=require("fs"),path=require(_0x3efa78(499)),resultMsgs={success:{code:0,message:"Success."},missingZip:{code:-1,message:_0x3efa78(519)},aboveFileSize:{code:-2,message:_0x3efa78(508)},aboveFileAmount:{code:-3,message:_0x3efa78(535)},invalidFileName:{code:-4,message:_0x3efa78(507)},invalidZip:{code:-5,message:_0x3efa78(502)},invalidParams:{code:-6,message:_0x3efa78(542)},extractFailed:{code:-7,message:_0x3efa78(529)}},FILE_MAX_SIZE=524288e3,FILE_MAX_AMOUNT=1e5,FILE_NAME_REGEXP=/\.\.\\/,ZipController=function(){var s=_0x3efa78;function r(e){var t=_0xbd42;_classCallCheck(this,r),this[t(483)]=e,this.checkDone=!1,this.checkResult,this[t(487)](),this[t(493)]()}return _createClass(r,[{key:s(487),value:function(){var e=s;fs[e(551)](this[e(483)])||this.setCheckResult(resultMsgs[e(527)])}},{key:"checkZipValid",value:function(){var e=s;if(!this[e(518)])try{this[e(557)]=new AdmZip(this[e(483)])}catch(e){this.setCheckResult(resultMsgs.invalidZip)}}},{key:"setCheckResult",value:function(e){var t=s;this[t(518)]||(this[t(518)]=!0,this[t(509)]=e)}},{key:"checkFileValid",value:function(e,t){var r=s;if(!this.checkDone)for(var i=this.zip[r(537)](),a=new RegExp(t),n=0;n<i[r(503)];n++){if(e<i[n][r(541)]()[r(481)])return void this[r(515)](resultMsgs[r(549)]);if(a.test(path[r(505)](i[n][r(492)])))return void this.setCheckResult(resultMsgs.invalidFileName)}}},{key:s(546),value:function(e){var t=s;this[t(518)]||e<this[t(557)].getEntryCount()&&this[t(515)](resultMsgs[t(543)])}},{key:"setCallback",value:function(e,t){e&&(this.callback=e,this.callbackArgs=t||[])}},{key:s(523),value:function(e,t){var r=s;if(!this[r(518)]){try{var i=e||"./";this[r(557)].extractAllTo(i,t),this[r(515)](resultMsgs.success)}catch(e){this[r(515)](resultMsgs.extractFailed),this.checkResult.message+=" error: ".concat(e[r(545)]())}this.callback&&this.resultMsgs===resultMsgs[r(552)]&&this.executeCallback()}}},{key:"executeCallback",value:function(){var t=s;try{this[t(538)].apply(this,[this[t(509)]][t(539)](_toConsumableArray(this[t(482)])))}catch(e){this.checkResult[t(530)]+=" callback error: ".concat(e[t(545)]())}}}]),r}();function unzip(f,h,p){return new Promise(function(e,t){var r,i,a,n,s,o,l,c=_0xbd42,u=Object[c(522)]({unlinkZip:!1,overwrite:!1,maxFileSize:FILE_MAX_SIZE,maxFilesAmount:FILE_MAX_AMOUNT,fileNameInvalidReg:FILE_NAME_REGEXP},p);checkUnzipParams(f,h,u)?(r=u[c(532)],i=u[c(548)],a=u[c(511)],n=u.maxFilesAmount,s=u[c(534)],o=u[c(538)],l=u[c(482)],(u=new ZipController(f))[c(531)](a,s),u.checkFilesAmount(n),u[c(491)](o,l),u[c(523)](h,i),r&&u.checkResult===resultMsgs.success&&fs[c(547)](f),e(u.checkResult)):e(resultMsgs[c(521)])})}function checkUnzipParams(e,t,r){var i=_0x3efa78;return typeof e===i(496)&&typeof t===i(496)&&("boolean"==typeof r[i(532)]&&typeof r[i(548)]===i(514)&&(typeof r[i(511)]===i(495)&&typeof r[i(555)]===i(495)&&((typeof r[i(534)]===i(496)||r.fileNameInvalidReg instanceof RegExp)&&((!r[i(538)]||r[i(538)]instanceof Function)&&!(r[i(482)]&&!Array.isArray(r.callbackArgs))))))}module.exports={unzip:unzip};