2
0

ZipEntry.php 12 KB

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