{“ast”:null,“code”:“'use strict';nnvar support = require('./support');nnvar base64 = require('./base64');nnvar nodejsUtils = require('./nodejsUtils');nnvar setImmediate = require('set-immediate-shim');nnvar external = require("./external");n/**n * Convert a string that pass as a "binary string": it should represent a byten * array but may have > 255 char codes. Be sure to take only the first byten * and returns the byte array.n * @param {String} str the string to transform.n * @return {Array|Uint8Array} the string in a binary format.n */nnnfunction string2binary(str) {n var result = null;nn if (support.uint8array) {n result = new Uint8Array(str.length);n } else {n result = new Array(str.length);n }nn return stringToArrayLike(str, result);n}n/**n * Create a new blob with the given content and the given type.n * @param {String|ArrayBuffer} part the content to put in the blob. DO NOT usen * an Uint8Array because the stock browser of android 4 won't accept it (itn * will be silently converted to a string, "[object Uint8Array]").n *n * Use only ONE part to build the blob to avoid a memory leak in IE11 / Edge:n * when a large amount of Array is used to create the Blob, the amount ofn * memory consumed is nearly 100 times the original data amount.n *n * @param {String} type the mime type of the blob.n * @return {Blob} the created blob.n */nnnexports.newBlob = function (part, type) {n exports.checkSupport("blob");nn try {n // Blob constructorn return new Blob(, {n type: typen });n } catch (e) {n try {n // deprecated, browser only, old wayn var Builder = self.BlobBuilder || self.WebKitBlobBuilder || self.MozBlobBuilder || self.MSBlobBuilder;n var builder = new Builder();n builder.append(part);n return builder.getBlob(type);n } catch (e) {n // well, fuck ?!n throw new Error("Bug : can't construct the Blob.");n }n }n};n/**n * The identity function.n * @param {Object} input the input.n * @return {Object} the same input.n */nnnfunction identity(input) {n return input;n}n/**n * Fill in an array with a string.n * @param {String} str the string to use.n * @param {Array|ArrayBuffer|Uint8Array|Buffer} array the array to fill in (will be mutated).n * @return {Array|ArrayBuffer|Uint8Array|Buffer} the updated array.n */nnnfunction stringToArrayLike(str, array) {n for (var i = 0; i < str.length; ++i) {n array = str.charCodeAt(i) & 0xFF;n }nn return array;n}n/**n * An helper for the function arrayLikeToString.n * This contains static informations and functions thatn * can be optimized by the browser JIT compiler.n */nnnvar arrayToStringHelper = {n /**n * Transform an array of int into a string, chunk by chunk.n * See the performances notes on arrayLikeToString.n * @param {Array|ArrayBuffer|Uint8Array|Buffer} array the array to transform.n * @param {String} type the type of the array.n * @param {Integer} chunk the chunk size.n * @return {String} the resulting string.n * @throws Error if the chunk is too big for the stack.n */n stringifyByChunk: function stringifyByChunk(array, type, chunk) {n var result = [],n k = 0,n len = array.length; // shortcutnn if (len <= chunk) {n return String.fromCharCode.apply(null, array);n }nn while (k < len) {n if (type === "array" || type === "nodebuffer") {n result.push(String.fromCharCode.apply(null, array.slice(k, Math.min(k + chunk, len))));n } else {n result.push(String.fromCharCode.apply(null, array.subarray(k, Math.min(k + chunk, len))));n }nn k += chunk;n }nn return result.join("");n },nn /**n * Call String.fromCharCode on every item in the array.n * This is the naive implementation, which generate A LOT of intermediate string.n * This should be used when everything else fail.n * @param {Array|ArrayBuffer|Uint8Array|Buffer} array the array to transform.n * @return {String} the result.n */n stringifyByChar: function stringifyByChar(array) {n var resultStr = "";nn for (var i = 0; i < array.length; i++) {n resultStr += String.fromCharCode(array);n }nn return resultStr;n },n applyCanBeUsed: {n /**n * true if the browser accepts to use String.fromCharCode on Uint8Arrayn */n uint8array: function () {n try {n return support.uint8array && String.fromCharCode.apply(null, new Uint8Array(1)).length === 1;n } catch (e) {n return false;n }n }(),nn /**n * true if the browser accepts to use String.fromCharCode on nodejs Buffer.n */n nodebuffer: function () {n try {n return support.nodebuffer && String.fromCharCode.apply(null, nodejsUtils.allocBuffer(1)).length === 1;n } catch (e) {n return false;n }n }()n }n};n/**n * Transform an array-like object to a string.n * @param {Array|ArrayBuffer|Uint8Array|Buffer} array the array to transform.n * @return {String} the result.n */nnfunction arrayLikeToString(array) {n // Performances notes :n // ——————–n // String.fromCharCode.apply(null, array) is the fastest, seen // see jsperf.com/converting-a-uint8array-to-a-string/2n // but the stack is limited (and we can get huge arrays !).n //n // result += String.fromCharCode(array); generate too many strings !n //n // This code is inspired by jsperf.com/arraybuffer-to-string-apply-performance/2n // TODO : we now have workers that split the work. Do we still need that ?n var chunk = 65536,n type = exports.getTypeOf(array),n canUseApply = true;nn if (type === "uint8array") {n canUseApply = arrayToStringHelper.applyCanBeUsed.uint8array;n } else if (type === "nodebuffer") {n canUseApply = arrayToStringHelper.applyCanBeUsed.nodebuffer;n }nn if (canUseApply) {n while (chunk > 1) {n try {n return arrayToStringHelper.stringifyByChunk(array, type, chunk);n } catch (e) {n chunk = Math.floor(chunk / 2);n }n }n } // no apply or chunk error : slow and painful algorithmn // default browser on android 4.*nnn return arrayToStringHelper.stringifyByChar(array);n}nnexports.applyFromCharCode = arrayLikeToString;n/**n * Copy
the data from an array-like to an other array-like.n * @param {Array|ArrayBuffer|Uint8Array|Buffer} arrayFrom the origin array.n * @param {Array|ArrayBuffer|Uint8Array|Buffer} arrayTo the destination array which will be mutated.n * @return {Array|ArrayBuffer|Uint8Array|Buffer} the updated destination array.n */nnfunction arrayLikeToArrayLike(arrayFrom, arrayTo) {n for (var i = 0; i < arrayFrom.length; i++) {n arrayTo = arrayFrom;n }nn return arrayTo;n} // a matrix containing functions to transform everything into everything.nnnvar transform = {}; // string to ?nntransform = {n "string": identity,n "array": function array(input) {n return stringToArrayLike(input, new Array(input.length));n },n "arraybuffer": function arraybuffer(input) {n return transform["uint8array"](input).buffer;n },n "uint8array": function uint8array(input) {n return stringToArrayLike(input, new Uint8Array(input.length));n },n "nodebuffer": function nodebuffer(input) {n return stringToArrayLike(input, nodejsUtils.allocBuffer(input.length));n }n}; // array to ?nntransform = {n "string": arrayLikeToString,n "array": identity,n "arraybuffer": function arraybuffer(input) {n return new Uint8Array(input).buffer;n },n "uint8array": function uint8array(input) {n return new Uint8Array(input);n },n "nodebuffer": function nodebuffer(input) {n return nodejsUtils.newBufferFrom(input);n }n}; // arraybuffer to ?nntransform = {n "string": function string(input) {n return arrayLikeToString(new Uint8Array(input));n },n "array": function array(input) {n return arrayLikeToArrayLike(new Uint8Array(input), new Array(input.byteLength));n },n "arraybuffer": identity,n "uint8array": function uint8array(input) {n return new Uint8Array(input);n },n "nodebuffer": function nodebuffer(input) {n return nodejsUtils.newBufferFrom(new Uint8Array(input));n }n}; // uint8array to ?nntransform = {n "string": arrayLikeToString,n "array": function array(input) {n return arrayLikeToArrayLike(input, new Array(input.length));n },n "arraybuffer": function arraybuffer(input) {n return input.buffer;n },n "uint8array": identity,n "nodebuffer": function nodebuffer(input) {n return nodejsUtils.newBufferFrom(input);n }n}; // nodebuffer to ?nntransform = {n "string": arrayLikeToString,n "array": function array(input) {n return arrayLikeToArrayLike(input, new Array(input.length));n },n "arraybuffer": function arraybuffer(input) {n return transform["uint8array"](input).buffer;n },n "uint8array": function uint8array(input) {n return arrayLikeToArrayLike(input, new Uint8Array(input.length));n },n "nodebuffer": identityn};n/**n * Transform an input into any type.n * The supported output type are : string, array, uint8array, arraybuffer, nodebuffer.n * If no output type is specified, the unmodified input will be returned.n * @param {String} outputType the output type.n * @param {String|Array|ArrayBuffer|Uint8Array|Buffer} input the input to convert.n * @throws {Error} an Error if the browser doesn't support the requested output type.n */nnexports.transformTo = function (outputType, input) {n if (!input) {n // undefined, null, etcn // an empty string won't harm.n input = "";n }nn if (!outputType) {n return input;n }nn exports.checkSupport(outputType);n var inputType = exports.getTypeOf(input);n var result = transform[outputType](input);n return result;n};n/**n * Return the type of the input.n * The type will be in a format valid for JSZip.utils.transformTo : string, array, uint8array, arraybuffer.n * @param {Object} input the input to identify.n * @return {String} the (lowercase) type of the input.n */nnnexports.getTypeOf = function (input) {n if (typeof input === "string") {n return "string";n }nn if (Object.prototype.toString.call(input) === "[object Array]") {n return "array";n }nn if (support.nodebuffer && nodejsUtils.isBuffer(input)) {n return "nodebuffer";n }nn if (support.uint8array && input instanceof Uint8Array) {n return "uint8array";n }nn if (support.arraybuffer && input instanceof ArrayBuffer) {n return "arraybuffer";n }n};n/**n * Throw an exception if the type is not supported.n * @param {String} type the type to check.n * @throws {Error} an Error if the browser doesn't support the requested type.n */nnnexports.checkSupport = function (type) {n var supported = support;nn if (!supported) {n throw new Error(type + " is not supported by this platform");n }n};nnexports.MAX_VALUE_16BITS = 65535;nexports.MAX_VALUE_32BITS = -1; // well, "\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF" is parsed as -1nn/**n * Prettify a string read as binary.n * @param {string} str the string to prettify.n * @return {string} a pretty string.n */nnexports.pretty = function (str) {n var res = '',n code,n i;nn for (i = 0; i < (str || "").length; i++) {n code = str.charCodeAt(i);n res += '\\x' + (code < 16 ? "0" : "") + code.toString(16).toUpperCase();n }nn return res;n};n/**n * Defer the call of a function.n * @param {Function} callback the function to call asynchronously.n * @param {Array} args the arguments to give to the callback.n */nnnexports.delay = function (callback, args, self) {n setImmediate(function () {n callback.apply(self || null, args || []);n });n};n/**n * Extends a prototype with an other, without calling a constructor withn * side effects. Inspired by nodejs' `utils.inherits`n * @param {Function} ctor the constructor to augmentn * @param {Function} superCtor the parent constructor to usen */nnnexports.inherits = function (ctor, superCtor) {n var Obj = function Obj() {};nn Obj.prototype = superCtor.prototype;n ctor.prototype = new Obj();n};n/**n * Merge the objects passed as parameters into a new one.n * @privaten * @param {…Object} var_args All objects to merge.n * @return {Object} a new object with the data of the others.n */nnnexports.extend = function () {n var result = {},n i,n attr;nn for (i = 0; i < arguments.length; i++) {n // arguments is not enumerable in some browsersn for (attr in arguments) {n if (arguments.hasOwnProperty(attr) && typeof result === "undefined") {n result = arguments[attr];n }n }n }nn return result;n};n/**n * Transform arbitrary content into a Promise.n * @param {String} name a name for the content being processed.n * @param {Object} inputData the content to process.n * @param {Boolean} isBinary true if the content is not an unicode stringn * @param {Boolean} isOptimizedBinaryString true if the string content only has one byte per character.n * @param {Boolean} isBase64 true if the string content is encoded with base64.n * @return {Promise} a promise in a format usable by JSZip.n */nnnexports.prepareContent = function (name, inputData, isBinary, isOptimizedBinaryString, isBase64) {n // if inputData is already a promise, this flatten it.n var promise = external.Promise.resolve(inputData).then(function (data) {n var isBlob = support.blob && (data instanceof Blob || ['[object File]', '[object Blob]'].indexOf(Object.prototype.toString.call(data)) !== -1);nn if (isBlob && typeof FileReader !== "undefined") {n return new external.Promise(function (resolve, reject) {n var reader = new FileReader();nn reader.onload = function (e) {n resolve(e.target.result);n };nn reader.onerror = function (e) {n reject(e.target.error);n };nn reader.readAsArrayBuffer(data);n });n } else {n return data;n }n });n return promise.then(function (data) {n var dataType = exports.getTypeOf(data);nn if (!dataType) {n return external.Promise.reject(new Error("Can't read the data of '" + name + "'. Is it " + "in a supported JavaScript type (String, Blob, ArrayBuffer, etc) ?"));n } // special case : it's way easier to work with Uint8Array than with ArrayBuffernnn if (dataType === "arraybuffer") {n data = exports.transformTo("uint8array", data);n } else if (dataType === "string") {n if (isBase64) {n data = base64.decode(data);n } else if (isBinary) {n // optimizedBinaryString === true means that the file has already been filtered with a 0xFF maskn if (isOptimizedBinaryString !== true) {n // this is a string, not in a base64 format.n // Be sure that this is a correct "binary string"n data = string2binary(data);n }n }n }nn return data;n });n};”,“map”:null,“metadata”:{},“sourceType”:“module”}