app-info-parser
Version:
Exact info from apk or ipa file.
73 lines (71 loc) • 3.75 kB
JavaScript
;
function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a 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, _toPropertyKey(descriptor.key), descriptor); } }
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
var Unzip = require('isomorphic-unzip');
var _require = require('./utils'),
isBrowser = _require.isBrowser,
decodeNullUnicode = _require.decodeNullUnicode;
var Zip = /*#__PURE__*/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);
}
/**
* get entries by regexps, the return format is: { <filename>: <Buffer|Blob> }
* @param {Array} regexps // regexps for matching files
* @param {String} type // return type, can be buffer or blob, default buffer
*/
_createClass(Zip, [{
key: "getEntries",
value: function getEntries(regexps) {
var _this = this;
var type = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 'buffer';
regexps = regexps.map(function (regex) {
return decodeNullUnicode(regex);
});
return new Promise(function (resolve, reject) {
_this.unzip.getBuffer(regexps, {
type: type
}, function (err, buffers) {
err ? reject(err) : resolve(buffers);
});
});
}
/**
* get entry by regex, return an instance of Buffer or Blob
* @param {Regex} regex // regex for matching file
* @param {String} type // return type, can be buffer or blob, default buffer
*/
}, {
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;