1 jls.loader.provide('jls.util.zip.ZipEntry'); 2 3 jls.loader.require('jls.lang.Struct'); 4 5 /** 6 * @namespace Provides classes for reading ZIPped data. 7 * @name jls.util.zip 8 */ 9 10 /* 11 * specs from pkzip APPNOTE 12 * All values are stored in little-endian byte order. 13 * 0x06054b50 => 0x50, 0x4b, 0x05, 0x06 14 */ 15 jls.util.zip.ZipEntry = jls.lang.Class.create( /** @lends jls.util.zip.ZipEntry.prototype */ 16 { 17 /** 18 * Creates a zip entry. 19 * 20 * @param {String} name The entry name. 21 * @constructs 22 * @class This class represents a zip entry. 23 */ 24 initialize : function(name, comment, extra, str) { 25 this._name = name; 26 this._comment = comment; 27 this._extra = extra; 28 this._compressedSize = 0; 29 this._crc = null; 30 this._method = null; 31 this._size = 0; 32 this._time = null; 33 this._offset = 0; 34 if ((typeof str != 'undefined') && (str instanceof jls.lang.Struct)) { 35 this._compressedSize = str.get('compressedSize'); 36 this._crc = str.get('crc32'); 37 this._method = str.get('compressionMethod'); 38 this._size = str.get('uncompressedSize'); 39 /* 40 * MS DOS Date & Time 41 * bits: day(1 - 31), month(1 - 12), years(from 1980): 5, 4, 7 - second, minute, hour: 5, 6, 5 42 */ 43 var time = str.get('lastModFileTime'); 44 var date = str.get('lastModFileDate'); 45 this._time = new Date(); 46 this._time.setUTCFullYear(1980 + ((date >>> 9) & 0x007f)); 47 this._time.setUTCMonth(((date >>> 5) & 0x000f) - 1); 48 this._time.setUTCDate(date & 0x001f); 49 this._time.setUTCHours((time >>> 11) & 0x001f); 50 this._time.setUTCMinutes((time >>> 5) & 0x003f); 51 this._time.setUTCSeconds(time & 0x001f); 52 this._time.setUTCMilliseconds(0); 53 jls.logger.debug('date: ' + this._time.toJSON()); 54 if (str.has('relativeOffset')) { 55 this._offset = str.get('relativeOffset'); 56 } 57 } 58 }, 59 /** 60 * Returns the compressed size. 61 * 62 * @returns {Number} The compressed size. 63 */ 64 getCompressedSize : function() { 65 return this._compressedSize; 66 }, 67 /** 68 * Returns the file comment. 69 * 70 * @returns {String} The file comment. 71 */ 72 getComment : function() { 73 return this._comment; 74 }, 75 /** 76 * Returns the CRC. 77 * 78 * @returns {Number} The CRC. 79 */ 80 getCrc : function() { 81 return this._crc; 82 }, 83 getExtra : function() { 84 return this._extra; 85 }, 86 /** 87 * Returns the compression method. 88 * 89 * @returns {Number} The compression method. 90 */ 91 getMethod : function() { 92 return this._method; 93 }, 94 /** 95 * Returns the file name. 96 * 97 * @returns {String} The file name. 98 */ 99 getName : function() { 100 return this._name; 101 }, 102 /** 103 * Returns the uncompressed size. 104 * 105 * @returns {Number} The uncompressed size. 106 */ 107 getSize : function() { 108 return this._size; 109 }, 110 /** 111 * Returns the last modification date. 112 * 113 * @returns {Date} The last modification date. 114 */ 115 getTime : function() { 116 return this._time; 117 }, 118 getOffset : function() { 119 return this._offset; 120 } 121 }); 122 123 Object.extend(jls.util.zip.ZipEntry, /** @lends jls.util.zip.ZipEntry */ 124 { 125 COMPRESSION_METHOD_STORED : 0, 126 COMPRESSION_METHOD_DEFLATED : 8, 127 GENERAL_PURPOSE_DEFLATE_MASK : 0x0006, 128 GENERAL_PURPOSE_DEFLATE_NORMAL : 0x0000, 129 GENERAL_PURPOSE_DEFLATE_MAXIMUM : 0x0002, 130 GENERAL_PURPOSE_DEFLATE_FAST : 0x0004, 131 GENERAL_PURPOSE_DEFLATE_SUPER_FAST : 0x0006, 132 GENERAL_PURPOSE_DATA_DESCRIPTOR : 0x0008, 133 GENERAL_PURPOSE_LANGUAGE_ENCODING : 0x0800, 134 LOCAL_FILE_HEADER_SIGNATURE : 0x04034b50, 135 FILE_HEADER_SIGNATURE : 0x02014b50, 136 END_CENTRAL_DIR_SIGNATURE : 0x06054b50, 137 getEndOfCentralDirectoryRecordStructDefinition : function() { 138 return [ 139 {name: 'signature', type: 'UnsignedInt'}, 140 {name: 'diskNumber', type: 'UnsignedShort'}, 141 {name: 'centralDirectoryDiskNumber', type: 'UnsignedShort'}, 142 {name: 'diskEntryCount', type: 'UnsignedShort'}, 143 {name: 'entryCount', type: 'UnsignedShort'}, 144 {name: 'size', type: 'UnsignedInt'}, 145 {name: 'offset', type: 'UnsignedInt'}, 146 {name: 'commentLength', type: 'UnsignedShort'} 147 ]; // 22 148 }, 149 getDataDescriptorStructDefinition : function() { 150 return [ 151 {name: 'crc32', type: 'UnsignedInt'}, 152 {name: 'compressedSize', type: 'UnsignedInt'}, 153 {name: 'uncompressedSize', type: 'UnsignedInt'} 154 ]; // 12 155 }, 156 getLocalFileHeaderStructDefinition : function() { 157 return [ 158 {name: 'signature', type: 'UnsignedInt'}, 159 {name: 'versionNeeded', type: 'UnsignedShort'}, 160 {name: 'generalPurposeBitFlag', type: 'UnsignedShort'}, 161 {name: 'compressionMethod', type: 'UnsignedShort'}, 162 {name: 'lastModFileTime', type: 'UnsignedShort'}, 163 {name: 'lastModFileDate', type: 'UnsignedShort'}, 164 {name: 'crc32', type: 'UnsignedInt'}, 165 {name: 'compressedSize', type: 'UnsignedInt'}, 166 {name: 'uncompressedSize', type: 'UnsignedInt'}, 167 {name: 'filenameLength', type: 'UnsignedShort'}, 168 {name: 'extraFieldLength', type: 'UnsignedShort'} 169 ]; // 30 170 }, 171 getFileHeaderStructDefinition : function() { 172 return [ 173 {name: 'signature', type: 'UnsignedInt'}, 174 {name: 'versionMadeBy', type: 'UnsignedShort'}, 175 {name: 'versionNeeded', type: 'UnsignedShort'}, 176 {name: 'generalPurposeBitFlag', type: 'UnsignedShort'}, 177 {name: 'compressionMethod', type: 'UnsignedShort'}, 178 {name: 'lastModFileTime', type: 'UnsignedShort'}, 179 {name: 'lastModFileDate', type: 'UnsignedShort'}, 180 {name: 'crc32', type: 'UnsignedInt'}, 181 {name: 'compressedSize', type: 'UnsignedInt'}, 182 {name: 'uncompressedSize', type: 'UnsignedInt'}, 183 {name: 'filenameLength', type: 'UnsignedShort'}, 184 {name: 'extraFieldLength', type: 'UnsignedShort'}, 185 {name: 'fileCommentLength', type: 'UnsignedShort'}, 186 {name: 'diskNumberStart', type: 'UnsignedShort'}, 187 {name: 'internalFileAttributes', type: 'UnsignedShort'}, 188 {name: 'externalFileAttributes', type: 'UnsignedInt'}, 189 {name: 'relativeOffset', type: 'UnsignedInt'} 190 ]; // 46 191 } 192 }); 193