ZipEntry.php 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431
  1. <?php
  2. namespace PhpZip\Model;
  3. use PhpZip\Exception\ZipException;
  4. use PhpZip\Extra\ExtraFieldsCollection;
  5. use PhpZip\ZipFileInterface;
  6. /**
  7. * ZIP file entry.
  8. *
  9. * @see https://pkware.cachefly.net/webdocs/casestudies/APPNOTE.TXT .ZIP File Format Specification
  10. * @author Ne-Lexa alexey@nelexa.ru
  11. * @license MIT
  12. */
  13. interface ZipEntry
  14. {
  15. // Bit masks for initialized fields.
  16. const BIT_PLATFORM = 1,
  17. BIT_METHOD = 2 /* 1 << 1 */,
  18. BIT_CRC = 2 /* 1 << 2 */,
  19. BIT_DATE_TIME = 64 /* 1 << 6 */,
  20. BIT_EXTERNAL_ATTR = 128 /* 1 << 7*/
  21. ;
  22. /** The unknown value for numeric properties. */
  23. const UNKNOWN = -1;
  24. /** Windows platform. */
  25. const PLATFORM_FAT = 0;
  26. /** Unix platform. */
  27. const PLATFORM_UNIX = 3;
  28. /** MacOS platform */
  29. const PLATFORM_OS_X = 19;
  30. /**
  31. * Pseudo compression method for WinZip AES encrypted entries.
  32. * Require php extension openssl or mcrypt.
  33. */
  34. const METHOD_WINZIP_AES = 99;
  35. /** General Purpose Bit Flag mask for encrypted data. */
  36. const GPBF_ENCRYPTED = 1; // 1 << 0
  37. // (For Methods 8 and 9 - Deflating)
  38. // Bit 2 Bit 1
  39. // 0 0 Normal compression
  40. // 0 1 Maximum compression
  41. // 1 0 Fast compression
  42. // 1 1 Super Fast compression
  43. const GPBF_COMPRESSION_FLAG1 = 2; // 1 << 1
  44. const GPBF_COMPRESSION_FLAG2 = 4; // 1 << 2
  45. /** General Purpose Bit Flag mask for data descriptor. */
  46. const GPBF_DATA_DESCRIPTOR = 8; // 1 << 3
  47. /** General Purpose Bit Flag mask for strong encryption. */
  48. const GPBF_STRONG_ENCRYPTION = 64; // 1 << 6
  49. /** General Purpose Bit Flag mask for UTF-8. */
  50. const GPBF_UTF8 = 2048; // 1 << 11
  51. /** Local File Header signature. */
  52. const LOCAL_FILE_HEADER_SIG = 0x04034B50;
  53. /** Data Descriptor signature. */
  54. const DATA_DESCRIPTOR_SIG = 0x08074B50;
  55. /**
  56. * The minimum length of the Local File Header record.
  57. *
  58. * local file header signature 4
  59. * version needed to extract 2
  60. * general purpose bit flag 2
  61. * compression method 2
  62. * last mod file time 2
  63. * last mod file date 2
  64. * crc-32 4
  65. * compressed size 4
  66. * uncompressed size 4
  67. * file name length 2
  68. * extra field length 2
  69. */
  70. const LOCAL_FILE_HEADER_MIN_LEN = 30;
  71. /**
  72. * Local File Header signature 4
  73. * Version Needed To Extract 2
  74. * General Purpose Bit Flags 2
  75. * Compression Method 2
  76. * Last Mod File Time 2
  77. * Last Mod File Date 2
  78. * CRC-32 4
  79. * Compressed Size 4
  80. * Uncompressed Size 4
  81. */
  82. const LOCAL_FILE_HEADER_FILE_NAME_LENGTH_POS = 26;
  83. /**
  84. * Default compression level for bzip2
  85. */
  86. const LEVEL_DEFAULT_BZIP2_COMPRESSION = 4;
  87. /**
  88. * Returns the ZIP entry name.
  89. *
  90. * @return string
  91. */
  92. public function getName();
  93. /**
  94. * Set entry name.
  95. *
  96. * @param string $name New entry name
  97. * @return ZipEntry
  98. * @throws ZipException
  99. */
  100. public function setName($name);
  101. /**
  102. * @return int Get platform
  103. */
  104. public function getPlatform();
  105. /**
  106. * Set platform
  107. *
  108. * @param int $platform
  109. * @return ZipEntry
  110. * @throws ZipException
  111. */
  112. public function setPlatform($platform);
  113. /**
  114. * Version needed to extract.
  115. *
  116. * @return int
  117. */
  118. public function getVersionNeededToExtract();
  119. /**
  120. * Set version needed to extract.
  121. *
  122. * @param int $version
  123. * @return ZipEntry
  124. */
  125. public function setVersionNeededToExtract($version);
  126. /**
  127. * @return bool
  128. */
  129. public function isZip64ExtensionsRequired();
  130. /**
  131. * Returns the compressed size of this entry.
  132. *
  133. * @see int
  134. */
  135. public function getCompressedSize();
  136. /**
  137. * Sets the compressed size of this entry.
  138. *
  139. * @param int $compressedSize The Compressed Size.
  140. * @return ZipEntry
  141. * @throws ZipException
  142. */
  143. public function setCompressedSize($compressedSize);
  144. /**
  145. * Returns the uncompressed size of this entry.
  146. *
  147. * @see ZipEntry::setCompressedSize
  148. */
  149. public function getSize();
  150. /**
  151. * Sets the uncompressed size of this entry.
  152. *
  153. * @param int $size The (Uncompressed) Size.
  154. * @return ZipEntry
  155. * @throws ZipException
  156. */
  157. public function setSize($size);
  158. /**
  159. * Return relative Offset Of Local File Header.
  160. *
  161. * @return int
  162. */
  163. public function getOffset();
  164. /**
  165. * @param int $offset
  166. * @return ZipEntry
  167. * @throws ZipException
  168. */
  169. public function setOffset($offset);
  170. /**
  171. * Returns true if and only if this ZIP entry represents a directory entry
  172. * (i.e. end with '/').
  173. *
  174. * @return bool
  175. */
  176. public function isDirectory();
  177. /**
  178. * Returns the General Purpose Bit Flags.
  179. *
  180. * @return int
  181. */
  182. public function getGeneralPurposeBitFlags();
  183. /**
  184. * Sets the General Purpose Bit Flags.
  185. *
  186. * @var int general
  187. * @return ZipEntry
  188. * @throws ZipException
  189. */
  190. public function setGeneralPurposeBitFlags($general);
  191. /**
  192. * Returns the indexed General Purpose Bit Flag.
  193. *
  194. * @param int $mask
  195. * @return bool
  196. */
  197. public function getGeneralPurposeBitFlag($mask);
  198. /**
  199. * Sets the indexed General Purpose Bit Flag.
  200. *
  201. * @param int $mask
  202. * @param bool $bit
  203. * @return ZipEntry
  204. */
  205. public function setGeneralPurposeBitFlag($mask, $bit);
  206. /**
  207. * Returns true if and only if this ZIP entry is encrypted.
  208. *
  209. * @return bool
  210. */
  211. public function isEncrypted();
  212. /**
  213. * Sets the encryption flag for this ZIP entry.
  214. *
  215. * @param bool $encrypted
  216. * @return ZipEntry
  217. */
  218. public function setEncrypted($encrypted);
  219. /**
  220. * Sets the encryption property to false and removes any other
  221. * encryption artifacts.
  222. *
  223. * @return ZipEntry
  224. */
  225. public function disableEncryption();
  226. /**
  227. * Returns the compression method for this entry.
  228. *
  229. * @return int
  230. */
  231. public function getMethod();
  232. /**
  233. * Sets the compression method for this entry.
  234. *
  235. * @param int $method
  236. * @return ZipEntry
  237. * @throws ZipException If method is not STORED, DEFLATED, BZIP2 or UNKNOWN.
  238. */
  239. public function setMethod($method);
  240. /**
  241. * Get Unix Timestamp
  242. *
  243. * @return int
  244. */
  245. public function getTime();
  246. /**
  247. * Set time from unix timestamp.
  248. *
  249. * @param int $unixTimestamp
  250. * @return ZipEntry
  251. */
  252. public function setTime($unixTimestamp);
  253. /**
  254. * Get Dos Time
  255. *
  256. * @return int
  257. */
  258. public function getDosTime();
  259. /**
  260. * Set Dos Time
  261. * @param int $dosTime
  262. * @throws ZipException
  263. */
  264. public function setDosTime($dosTime);
  265. /**
  266. * Returns the external file attributes.
  267. *
  268. * @return int The external file attributes.
  269. */
  270. public function getExternalAttributes();
  271. /**
  272. * Sets the external file attributes.
  273. *
  274. * @param int $externalAttributes the external file attributes.
  275. * @return ZipEntry
  276. * @throws ZipException
  277. */
  278. public function setExternalAttributes($externalAttributes);
  279. /**
  280. * @return ExtraFieldsCollection
  281. */
  282. public function getExtraFieldsCollection();
  283. /**
  284. * Returns a protective copy of the serialized Extra Fields.
  285. *
  286. * @return string A new byte array holding the serialized Extra Fields.
  287. * null is never returned.
  288. */
  289. public function getExtra();
  290. /**
  291. * Sets the serialized Extra Fields by making a protective copy.
  292. * Note that this method parses the serialized Extra Fields according to
  293. * the ZIP File Format Specification and limits its size to 64 KB.
  294. * Therefore, this property cannot not be used to hold arbitrary
  295. * (application) data.
  296. * Consider storing such data in a separate entry instead.
  297. *
  298. * @param string $data The byte array holding the serialized Extra Fields.
  299. * @throws ZipException if the serialized Extra Fields exceed 64 KB
  300. */
  301. public function setExtra($data);
  302. /**
  303. * Returns comment entry
  304. *
  305. * @return string
  306. */
  307. public function getComment();
  308. /**
  309. * Set entry comment.
  310. *
  311. * @param $comment
  312. * @return ZipEntry
  313. */
  314. public function setComment($comment);
  315. /**
  316. * @return bool
  317. */
  318. public function isDataDescriptorRequired();
  319. /**
  320. * Return crc32 content or 0 for WinZip AES v2
  321. *
  322. * @return int
  323. */
  324. public function getCrc();
  325. /**
  326. * Set crc32 content.
  327. *
  328. * @param int $crc
  329. * @return ZipEntry
  330. * @throws ZipException
  331. */
  332. public function setCrc($crc);
  333. /**
  334. * @return string
  335. */
  336. public function getPassword();
  337. /**
  338. * Set password and encryption method from entry
  339. *
  340. * @param string $password
  341. * @param null|int $encryptionMethod
  342. * @return ZipEntry
  343. */
  344. public function setPassword($password, $encryptionMethod = null);
  345. /**
  346. * @return int
  347. */
  348. public function getEncryptionMethod();
  349. /**
  350. * Set encryption method
  351. *
  352. * @see ZipFileInterface::ENCRYPTION_METHOD_TRADITIONAL
  353. * @see ZipFileInterface::ENCRYPTION_METHOD_WINZIP_AES_128
  354. * @see ZipFileInterface::ENCRYPTION_METHOD_WINZIP_AES_192
  355. * @see ZipFileInterface::ENCRYPTION_METHOD_WINZIP_AES_256
  356. *
  357. * @param int $encryptionMethod
  358. * @return ZipEntry
  359. * @throws ZipException
  360. */
  361. public function setEncryptionMethod($encryptionMethod);
  362. /**
  363. * Returns an string content of the given entry.
  364. *
  365. * @return null|string
  366. * @throws ZipException
  367. */
  368. public function getEntryContent();
  369. /**
  370. * @param int $compressionLevel
  371. * @return ZipEntry
  372. */
  373. public function setCompressionLevel($compressionLevel = ZipFileInterface::LEVEL_DEFAULT_COMPRESSION);
  374. /**
  375. * @return int
  376. */
  377. public function getCompressionLevel();
  378. }