{“ast”:null,“code”:“'use strict';nnvar readerFor = require('./reader/readerFor');nnvar utils = require('./utils');nnvar CompressedObject = require('./compressedObject');nnvar crc32fn = require('./crc32');nnvar utf8 = require('./utf8');nnvar compressions = require('./compressions');nnvar support = require('./support');nnvar MADE_BY_DOS = 0x00;nvar MADE_BY_UNIX = 0x03;n/**n * Find a compression registered in JSZip.n * @param {string} compressionMethod the method magic to find.n * @return {Object|null} the JSZip compression object, null if none found.n */nnvar findCompression = function findCompression(compressionMethod) {n for (var method in compressions) {n if (!compressions.hasOwnProperty(method)) {n continue;n }nn if (compressions.magic === compressionMethod) {n return compressions;n }n }nn return null;n}; // class ZipEntry {{{nn/**n * An entry in the zip file.n * @constructorn * @param {Object} options Options of the current file.n * @param {Object} loadOptions Options for loading the stream.n */nnnfunction ZipEntry(options, loadOptions) {n this.options = options;n this.loadOptions = loadOptions;n}nnZipEntry.prototype = {n /**n * say if the file is encrypted.n * @return {boolean} true if the file is encrypted, false otherwise.n */n isEncrypted: function isEncrypted() {n // bit 1 is setn return (this.bitFlag & 0x0001) === 0x0001;n },nn /**n * say if the file has utf-8 filename/comment.n * @return {boolean} true if the filename/comment is in utf-8, false otherwise.n */n useUTF8: function useUTF8() {n // bit 11 is setn return (this.bitFlag & 0x0800) === 0x0800;n },nn /**n * Read the local part of a zip file and add the info in this object.n * @param {DataReader} reader the reader to use.n */n readLocalPart: function readLocalPart(reader) {n var compression, localExtraFieldsLength; // we already know everything from the central dir !n // If the central dir data are false, we are doomed.n // On the bright side, the local part is scary : zip64, data descriptors, both, etc.n // The less data we get here, the more reliable this should be.n // Let's skip the whole header and dash to the data !nn reader.skip(22); // in some zip created on windows, the filename stored in the central dir contains \ instead of /.n // Strangely, the filename here is OK.n // I would love to treat these zip files as corrupted (see www.info-zip.org/FAQ.html#backslashesn // or APPNOTE#4.4.17.1, "All slashes MUST be forward slashes '/'") but there are a lot of bad zip generators…n // Search "unzip mismatching "local" filename continuing with "central" filename version" onn // the internet.n //n // I think I see the logic here : the central directory is used to displayn // content and the local directory is used to extract the files. Mixing / and \n // may be used to display \ to windows users and use / when extracting the files.n // Unfortunately, this lead also to some issues : seclists.org/fulldisclosure/2009/Sep/394nn this.fileNameLength = reader.readInt(2);n localExtraFieldsLength = reader.readInt(2); // can't be sure this will be the same as the central dirn // the fileName is stored as binary data, the handleUTF8 method will take care of the encoding.nn this.fileName = reader.readData(this.fileNameLength);n reader.skip(localExtraFieldsLength);nn if (this.compressedSize === -1 || this.uncompressedSize === -1) {n throw new Error("Bug or corrupted zip : didn't get enough informations from the central directory " + "(compressedSize === -1 || uncompressedSize === -1)");n }nn compression = findCompression(this.compressionMethod);nn if (compression === null) {n // no compression foundn throw new Error("Corrupted zip : compression " + utils.pretty(this.compressionMethod) + " unknown (inner file : " + utils.transformTo("string", this.fileName) + ")");n }nn this.decompressed = new CompressedObject(this.compressedSize, this.uncompressedSize, this.crc32, compression, reader.readData(this.compressedSize));n },nn /**n * Read the central part of a zip file and add the info in this object.n * @param {DataReader} reader the reader to use.n */n readCentralPart: function readCentralPart(reader) {n this.versionMadeBy = reader.readInt(2);n reader.skip(2); // this.versionNeeded = reader.readInt(2);nn this.bitFlag = reader.readInt(2);n this.compressionMethod = reader.readString(2);n this.date = reader.readDate();n this.crc32 = reader.readInt(4);n this.compressedSize = reader.readInt(4);n this.uncompressedSize = reader.readInt(4);n var fileNameLength = reader.readInt(2);n this.extraFieldsLength = reader.readInt(2);n this.fileCommentLength = reader.readInt(2);n this.diskNumberStart = reader.readInt(2);n this.internalFileAttributes = reader.readInt(2);n this.externalFileAttributes = reader.readInt(4);n this.localHeaderOffset = reader.readInt(4);nn if (this.isEncrypted()) {n throw new Error("Encrypted zip are not supported");n } // will be read in the local part, see the comments therennn reader.skip(fileNameLength);n this.readExtraFields(reader);n this.parseZIP64ExtraField(reader);n this.fileComment = reader.readData(this.fileCommentLength);n },nn /**n * Parse the external file attributes and get the unix/dos permissions.n */n processAttributes: function processAttributes() {n this.unixPermissions = null;n this.dosPermissions = null;n var madeBy = this.versionMadeBy >> 8; // Check if we have the DOS directory flag set.n // We look for it in the DOS and UNIX permissionsn // but some unknown platform could set it as a compatibility flag.nn this.dir = this.externalFileAttributes & 0x0010 ? true : false;nn if (madeBy === MADE_BY_DOS) {n // first 6 bits (0 to 5)n this.dosPermissions = this.externalFileAttributes & 0x3F;n }nn if (madeBy === MADE_BY_UNIX) {n this.unixPermissions = this.externalFileAttributes >> 16 & 0xFFFF; // the octal permissions are in (this.unixPermissions & 0x01FF).toString(8);n } // fail safe : if the name ends with a / it probably means a foldernnn if (!this.dir && this.fileNameStr.slice(-1) === '/') {n this.dir = true;n }n },nn /**n * Parse the ZIP64 extra field and merge the info in the current ZipEntry.n * @param {DataReader} reader the reader to use.n */n parseZIP64ExtraField: function parseZIP64ExtraField(reader) {n if (!this.extraFields) {n return;n } // should be something, preparing the extra readernnn var extraReader = readerFor(this.extraFields.value); // I really hope that these 64bits integer can fit in 32 bits integer, because jsn // won't let us have more.nn if (this.uncompressedSize === utils.MAX_VALUE_32BITS) {n this.uncompressedSize = extraReader.readInt(8);n }nn if (this.compressedSize === utils.MAX_VALUE_32BITS) {n this.compressedSize = extraReader.readInt(8);n }nn if (this.localHeaderOffset === utils.MAX_VALUE_32BITS) {n this.localHeaderOffset = extraReader.readInt(8);n }nn if (this.diskNumberStart === utils.MAX_VALUE_32BITS) {n this.diskNumberStart = extraReader.readInt(4);n }n },nn /**n * Read the central part of a zip file and add the info in this object.n * @param {DataReader} reader the reader to use.n */n readExtraFields: function readExtraFields(reader) {n var end = reader.index + this.extraFieldsLength,n extraFieldId,n extraFieldLength,n extraFieldValue;nn if (!this.extraFields) {n this.extraFields = {};n }nn while (reader.index < end) {n extraFieldId = reader.readInt(2);n extraFieldLength = reader.readInt(2);n extraFieldValue = reader.readData(extraFieldLength);n this.extraFields = {n id: extraFieldId,n length: extraFieldLength,n value: extraFieldValuen };n }n },nn /**n * Apply an UTF8 transformation if needed.n */n handleUTF8: function handleUTF8() {n var decodeParamType = support.uint8array ? "uint8array" : "array";nn if (this.useUTF8()) {n this.fileNameStr = utf8.utf8decode(this.fileName);n this.fileCommentStr = utf8.utf8decode(this.fileComment);n } else {n var upath = this.findExtraFieldUnicodePath();nn if (upath !== null) {n this.fileNameStr = upath;n } else {n // ASCII text or unsupported code pagen var fileNameByteArray = utils.transformTo(decodeParamType, this.fileName);n this.fileNameStr = this.loadOptions.decodeFileName(fileNameByteArray);n }nn var ucomment = this.findExtraFieldUnicodeComment();nn if (ucomment !== null) {n this.fileCommentStr = ucomment;n } else {n // ASCII text or unsupported code pagen var commentByteArray = utils.transformTo(decodeParamType, this.fileComment);n this.fileCommentStr = this.loadOptions.decodeFileName(commentByteArray);n }n }n },nn /**n * Find the unicode path declared in the extra field, if any.n * @return {String} the unicode path, null otherwise.n */n findExtraFieldUnicodePath: function findExtraFieldUnicodePath() {n var upathField = this.extraFields;nn if (upathField) {n var extraReader = readerFor(upathField.value); // wrong versionnn if (extraReader.readInt(1) !== 1) {n return null;n } // the crc of the filename changed, this field is out of date.nnn if (crc32fn(this.fileName) !== extraReader.readInt(4)) {n return null;n }nn return utf8.utf8decode(extraReader.readData(upathField.length - 5));n }nn return null;n },nn /**n * Find the unicode comment declared in the extra field, if any.n * @return {String} the unicode comment, null otherwise.n */n findExtraFieldUnicodeComment: function findExtraFieldUnicodeComment() {n var ucommentField = this.extraFields;nn if (ucommentField) {n var extraReader = readerFor(ucommentField.value); // wrong versionnn if (extraReader.readInt(1) !== 1) {n return null;n } // the crc of the comment changed, this field is out of date.nnn if (crc32fn(this.fileComment) !== extraReader.readInt(4)) {n return null;n }nn return utf8.utf8decode(extraReader.readData(ucommentField.length - 5));n }nn return null;n }n};nmodule.exports = ZipEntry;”,“map”:null,“metadata”:{},“sourceType”:“module”}