UNPKG

app-info-parser2

Version:

Exact info from apk or ipa file.

73 lines (58 loc) 2.7 kB
'use strict'; var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }(); function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } var Unzip = require('isomorphic-unzip'); var _require = require('./utils'), isBrowser = _require.isBrowser, decodeNullUnicode = _require.decodeNullUnicode; var Zip = function () { function Zip(file) { _classCallCheck(this, Zip); if (isBrowser()) { if (!(file instanceof window.Blob || typeof file.size !== 'undefined')) { throw new Error('Param error: [file] must be an instance of Blob or File in browser.'); } this.file = file; } else { if (typeof file !== 'string') { throw new Error('Param error: [file] must be file path in Node.'); } this.file = require('path').resolve(file); } this.unzip = new Unzip(this.file); } /** * 获取安装包文件,返回类型:{ <filename>: <Buffer|Blob> } * @param {Array} regexs // 匹配文件的正则表达式数组 * @param {String} type // 输出文件类型,默认buffer,type='blob'时返回blob */ _createClass(Zip, [{ key: 'getEntries', value: function getEntries(regexs) { var _this = this; var type = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 'buffer'; regexs = regexs.map(function (regex) { return decodeNullUnicode(regex); }); return new Promise(function (resolve, reject) { _this.unzip.getBuffer(regexs, { type: type }, function (err, buffers) { err ? reject(err) : resolve(buffers); }); }); } }, { key: 'getEntry', value: function getEntry(regex) { var _this2 = this; var type = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 'buffer'; regex = decodeNullUnicode(regex); return new Promise(function (resolve, reject) { _this2.unzip.getBuffer([regex], { type: type }, function (err, buffers) { err ? reject(err) : resolve(buffers[regex]); }); }); } }]); return Zip; }(); module.exports = Zip;