jszip-utils.min.js 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. !function (e) {
  2. "object" == typeof exports ? module.exports = e() : "function" == typeof define && define.amd ? define(e) : "undefined" != typeof window ? window.JSZipUtils = e() : "undefined" != typeof global ? global.JSZipUtils = e() : "undefined" != typeof self && (self.JSZipUtils = e())
  3. }(function () {
  4. var define, module, exports;
  5. return (function e(t, n, r) {
  6. function s(o, u) {
  7. if (!n[o]) {
  8. if (!t[o]) {
  9. var a = typeof require == "function" && require;
  10. if (!u && a) {
  11. return a(o, !0)
  12. }
  13. if (i) {
  14. return i(o, !0)
  15. }
  16. throw new Error("Cannot find module '" + o + "'")
  17. }
  18. var f = n[o] = {exports: {}};
  19. t[o][0].call(f.exports, function (e) {
  20. var n = t[o][1][e];
  21. return s(n ? n : e)
  22. }, f, f.exports, e, t, n, r)
  23. }
  24. return n[o].exports
  25. }
  26. var i = typeof require == "function" && require;
  27. for (var o = 0; o < r.length; o++) {
  28. s(r[o])
  29. }
  30. return s
  31. })({
  32. 1: [function (require, module, exports) {
  33. var JSZipUtils = {};
  34. JSZipUtils._getBinaryFromXHR = function (xhr) {
  35. return xhr.response || xhr.responseText
  36. };
  37. function createStandardXHR() {
  38. try {
  39. return new window.XMLHttpRequest()
  40. } catch (e) {
  41. }
  42. }
  43. function createActiveXHR() {
  44. try {
  45. return new window.ActiveXObject("Microsoft.XMLHTTP")
  46. } catch (e) {
  47. }
  48. }
  49. var createXHR = (typeof window !== "undefined" && window.ActiveXObject) ? function () {
  50. return createStandardXHR() || createActiveXHR()
  51. } : createStandardXHR;
  52. JSZipUtils.getBinaryContent = function (path, options) {
  53. var promise, resolve, reject;
  54. var callback;
  55. if (!options) {
  56. options = {}
  57. }
  58. if (typeof options === "function") {
  59. callback = options;
  60. options = {}
  61. } else {
  62. if (typeof options.callback === "function") {
  63. callback = options.callback
  64. }
  65. }
  66. if (!callback && typeof Promise !== "undefined") {
  67. promise = new Promise(function (_resolve, _reject) {
  68. resolve = _resolve;
  69. reject = _reject
  70. })
  71. } else {
  72. resolve = function (data) {
  73. callback(null, data)
  74. };
  75. reject = function (err) {
  76. callback(err, null)
  77. }
  78. }
  79. try {
  80. var xhr = createXHR();
  81. xhr.open("GET", path, true);
  82. if ("responseType" in xhr) {
  83. xhr.responseType = "arraybuffer"
  84. }
  85. if (xhr.overrideMimeType) {
  86. xhr.overrideMimeType("text/plain; charset=x-user-defined")
  87. }
  88. xhr.onreadystatechange = function (event) {
  89. if (xhr.readyState === 4) {
  90. if (xhr.status === 200 || xhr.status === 0) {
  91. try {
  92. resolve(JSZipUtils._getBinaryFromXHR(xhr))
  93. } catch (err) {
  94. reject(new Error(err))
  95. }
  96. } else {
  97. reject(new Error("Ajax error for " + path + " : " + this.status + " " + this.statusText))
  98. }
  99. }
  100. };
  101. if (options.progress) {
  102. xhr.onprogress = function (e) {
  103. options.progress({
  104. path: path,
  105. originalEvent: e,
  106. percent: e.loaded / e.total * 100,
  107. loaded: e.loaded,
  108. total: e.total
  109. })
  110. }
  111. }
  112. xhr.withCredentials = true;
  113. xhr.send()
  114. } catch (e) {
  115. reject(new Error(e), null)
  116. }
  117. return promise
  118. };
  119. module.exports = JSZipUtils
  120. }, {}]
  121. }, {}, [1])(1)
  122. });