ZipFileInterface.php 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902
  1. <?php
  2. namespace PhpZip;
  3. use PhpZip\Constants\ZipCompressionLevel;
  4. use PhpZip\Constants\ZipCompressionMethod;
  5. use PhpZip\Constants\ZipEncryptionMethod;
  6. use PhpZip\Exception\ZipEntryNotFoundException;
  7. use PhpZip\Exception\ZipException;
  8. use PhpZip\Model\ZipEntry;
  9. use PhpZip\Model\ZipEntryMatcher;
  10. use PhpZip\Model\ZipInfo;
  11. use Psr\Http\Message\ResponseInterface;
  12. use Symfony\Component\Finder\Finder;
  13. /**
  14. * Create, open .ZIP files, modify, get info and extract files.
  15. *
  16. * Implemented support traditional PKWARE encryption and WinZip AES encryption.
  17. * Implemented support ZIP64.
  18. * Support ZipAlign functional.
  19. *
  20. * @see https://pkware.cachefly.net/webdocs/casestudies/APPNOTE.TXT .ZIP File Format Specification
  21. *
  22. * @author Ne-Lexa alexey@nelexa.ru
  23. * @license MIT
  24. *
  25. * @deprecated will be removed in version 4.0. Use the {@see ZipFile} class.
  26. */
  27. interface ZipFileInterface extends \Countable, \ArrayAccess, \Iterator
  28. {
  29. /**
  30. * Method for Stored (uncompressed) entries.
  31. *
  32. * @see ZipEntry::setCompressionMethod()
  33. * @deprecated Use {@see ZipCompressionMethod::STORED}
  34. */
  35. const METHOD_STORED = ZipCompressionMethod::STORED;
  36. /**
  37. * Method for Deflated compressed entries.
  38. *
  39. * @see ZipEntry::setCompressionMethod()
  40. * @deprecated Use {@see ZipCompressionMethod::DEFLATED}
  41. */
  42. const METHOD_DEFLATED = ZipCompressionMethod::DEFLATED;
  43. /**
  44. * Method for BZIP2 compressed entries.
  45. * Require php extension bz2.
  46. *
  47. * @see ZipEntry::setCompressionMethod()
  48. * @deprecated Use {@see ZipCompressionMethod::BZIP2}
  49. */
  50. const METHOD_BZIP2 = ZipCompressionMethod::BZIP2;
  51. /**
  52. * @var int default compression level
  53. *
  54. * @deprecated Use {@see ZipCompressionLevel::NORMAL}
  55. */
  56. const LEVEL_DEFAULT_COMPRESSION = ZipCompressionLevel::NORMAL;
  57. /**
  58. * Compression level for fastest compression.
  59. *
  60. * @deprecated Use {@see ZipCompressionLevel::FAST}
  61. */
  62. const LEVEL_FAST = ZipCompressionLevel::FAST;
  63. /**
  64. * Compression level for fastest compression.
  65. *
  66. * @deprecated Use {@see ZipCompressionLevel::SUPER_FAST}
  67. */
  68. const LEVEL_BEST_SPEED = ZipCompressionLevel::SUPER_FAST;
  69. /** @deprecated Use {@see ZipCompressionLevel::SUPER_FAST} */
  70. const LEVEL_SUPER_FAST = ZipCompressionLevel::SUPER_FAST;
  71. /**
  72. * Compression level for best compression.
  73. *
  74. * @deprecated Use {@see ZipCompressionLevel::MAXIMUM}
  75. */
  76. const LEVEL_BEST_COMPRESSION = ZipCompressionLevel::MAXIMUM;
  77. /**
  78. * No specified method for set encryption method to Traditional PKWARE encryption.
  79. *
  80. * @deprecated Use {@see ZipEncryptionMethod::PKWARE}
  81. */
  82. const ENCRYPTION_METHOD_TRADITIONAL = ZipEncryptionMethod::PKWARE;
  83. /**
  84. * No specified method for set encryption method to WinZip AES encryption.
  85. * Default value 256 bit.
  86. *
  87. * @deprecated Use {@see ZipEncryptionMethod::WINZIP_AES_256}
  88. */
  89. const ENCRYPTION_METHOD_WINZIP_AES = ZipEncryptionMethod::WINZIP_AES_256;
  90. /**
  91. * No specified method for set encryption method to WinZip AES encryption 128 bit.
  92. *
  93. * @deprecated Use {@see ZipEncryptionMethod::WINZIP_AES_128}
  94. */
  95. const ENCRYPTION_METHOD_WINZIP_AES_128 = ZipEncryptionMethod::WINZIP_AES_128;
  96. /**
  97. * No specified method for set encryption method to WinZip AES encryption 194 bit.
  98. *
  99. * @deprecated Use {@see ZipEncryptionMethod::WINZIP_AES_192}
  100. */
  101. const ENCRYPTION_METHOD_WINZIP_AES_192 = ZipEncryptionMethod::WINZIP_AES_192;
  102. /**
  103. * No specified method for set encryption method to WinZip AES encryption 256 bit.
  104. *
  105. * @deprecated Use {@see ZipEncryptionMethod::WINZIP_AES_256}
  106. */
  107. const ENCRYPTION_METHOD_WINZIP_AES_256 = ZipEncryptionMethod::WINZIP_AES_256;
  108. /**
  109. * Open zip archive from file.
  110. *
  111. * @param string $filename
  112. * @param array $options
  113. *
  114. * @throws ZipException if can't open file
  115. *
  116. * @return ZipFile
  117. */
  118. public function openFile($filename, array $options = []);
  119. /**
  120. * Open zip archive from raw string data.
  121. *
  122. * @param string $data
  123. * @param array $options
  124. *
  125. * @throws ZipException if can't open temp stream
  126. *
  127. * @return ZipFile
  128. */
  129. public function openFromString($data, array $options = []);
  130. /**
  131. * Open zip archive from stream resource.
  132. *
  133. * @param resource $handle
  134. * @param array $options
  135. *
  136. * @throws ZipException
  137. *
  138. * @return ZipFile
  139. */
  140. public function openFromStream($handle, array $options = []);
  141. /**
  142. * @return string[] returns the list files
  143. */
  144. public function getListFiles();
  145. /**
  146. * @return int returns the number of entries in this ZIP file
  147. */
  148. public function count();
  149. /**
  150. * Returns the file comment.
  151. *
  152. * @return string|null the file comment
  153. */
  154. public function getArchiveComment();
  155. /**
  156. * Set archive comment.
  157. *
  158. * @param string|null $comment
  159. *
  160. * @return ZipFile
  161. */
  162. public function setArchiveComment($comment = null);
  163. /**
  164. * Checks if there is an entry in the archive.
  165. *
  166. * @param string $entryName
  167. *
  168. * @return bool
  169. */
  170. public function hasEntry($entryName);
  171. /**
  172. * Returns ZipEntry object.
  173. *
  174. * @param string $entryName
  175. *
  176. * @throws ZipEntryNotFoundException
  177. *
  178. * @return ZipEntry
  179. */
  180. public function getEntry($entryName);
  181. /**
  182. * Checks that the entry in the archive is a directory.
  183. * Returns true if and only if this ZIP entry represents a directory entry
  184. * (i.e. end with '/').
  185. *
  186. * @param string $entryName
  187. *
  188. * @throws ZipEntryNotFoundException
  189. *
  190. * @return bool
  191. */
  192. public function isDirectory($entryName);
  193. /**
  194. * Returns entry comment.
  195. *
  196. * @param string $entryName
  197. *
  198. * @throws ZipException
  199. * @throws ZipEntryNotFoundException
  200. *
  201. * @return string
  202. */
  203. public function getEntryComment($entryName);
  204. /**
  205. * Set entry comment.
  206. *
  207. * @param string $entryName
  208. * @param string|null $comment
  209. *
  210. * @throws ZipEntryNotFoundException
  211. * @throws ZipException
  212. *
  213. * @return ZipFile
  214. */
  215. public function setEntryComment($entryName, $comment = null);
  216. /**
  217. * Returns the entry contents.
  218. *
  219. * @param string $entryName
  220. *
  221. * @throws ZipEntryNotFoundException
  222. * @throws ZipException
  223. *
  224. * @return string
  225. */
  226. public function getEntryContents($entryName);
  227. /**
  228. * @param string $entryName
  229. *
  230. * @throws ZipEntryNotFoundException
  231. * @throws ZipException
  232. *
  233. * @return resource
  234. */
  235. public function getEntryStream($entryName);
  236. /**
  237. * Get info by entry.
  238. *
  239. * @param string|ZipEntry $entryName
  240. *
  241. * @throws ZipException
  242. * @throws ZipEntryNotFoundException
  243. *
  244. * @return ZipInfo
  245. */
  246. public function getEntryInfo($entryName);
  247. /**
  248. * Get info by all entries.
  249. *
  250. * @return ZipInfo[]
  251. */
  252. public function getAllInfo();
  253. /**
  254. * @return ZipEntryMatcher
  255. */
  256. public function matcher();
  257. /**
  258. * Extract the archive contents (unzip).
  259. *
  260. * Extract the complete archive or the given files to the specified destination.
  261. *
  262. * @param string $destDir location where to extract the files
  263. * @param array|string|null $entries entries to extract
  264. * @param array $options extract options
  265. * @param array $extractedEntries if the extractedEntries argument
  266. * is present, then the specified
  267. * array will be filled with
  268. * information about the
  269. * extracted entries
  270. *
  271. * @throws ZipException
  272. *
  273. * @return ZipFile
  274. */
  275. public function extractTo($destDir, $entries = null, array $options = [], &$extractedEntries = []);
  276. /**
  277. * Add entry from the string.
  278. *
  279. * @param string $entryName zip entry name
  280. * @param string $contents string contents
  281. * @param int|null $compressionMethod Compression method.
  282. * Use {@see ZipCompressionMethod::STORED},
  283. * {@see ZipCompressionMethod::DEFLATED} or
  284. * {@see ZipCompressionMethod::BZIP2}.
  285. * If null, then auto choosing method.
  286. *
  287. * @throws ZipException
  288. *
  289. * @return ZipFile
  290. */
  291. public function addFromString($entryName, $contents, $compressionMethod = null);
  292. /**
  293. * @param Finder $finder
  294. * @param array $options
  295. *
  296. * @throws ZipException
  297. *
  298. * @return ZipEntry[]
  299. */
  300. public function addFromFinder(Finder $finder, array $options = []);
  301. /**
  302. * @param \SplFileInfo $file
  303. * @param string|null $entryName
  304. * @param array $options
  305. *
  306. * @throws ZipException
  307. *
  308. * @return ZipEntry
  309. */
  310. public function addSplFile(\SplFileInfo $file, $entryName = null, array $options = []);
  311. /**
  312. * Add entry from the file.
  313. *
  314. * @param string $filename destination file
  315. * @param string|null $entryName zip Entry name
  316. * @param int|null $compressionMethod Compression method.
  317. * Use {@see ZipCompressionMethod::STORED},
  318. * {@see ZipCompressionMethod::DEFLATED} or
  319. * {@see ZipCompressionMethod::BZIP2}.
  320. * If null, then auto choosing method.
  321. *
  322. * @throws ZipException
  323. *
  324. * @return ZipFile
  325. */
  326. public function addFile($filename, $entryName = null, $compressionMethod = null);
  327. /**
  328. * Add entry from the stream.
  329. *
  330. * @param resource $stream stream resource
  331. * @param string $entryName zip Entry name
  332. * @param int|null $compressionMethod Compression method.
  333. * Use {@see ZipCompressionMethod::STORED},
  334. * {@see ZipCompressionMethod::DEFLATED} or
  335. * {@see ZipCompressionMethod::BZIP2}.
  336. * If null, then auto choosing method.
  337. *
  338. * @throws ZipException
  339. *
  340. * @return ZipFile
  341. */
  342. public function addFromStream($stream, $entryName, $compressionMethod = null);
  343. /**
  344. * Add an empty directory in the zip archive.
  345. *
  346. * @param string $dirName
  347. *
  348. * @throws ZipException
  349. *
  350. * @return ZipFile
  351. */
  352. public function addEmptyDir($dirName);
  353. /**
  354. * Add directory not recursively to the zip archive.
  355. *
  356. * @param string $inputDir Input directory
  357. * @param string $localPath add files to this directory, or the root
  358. * @param int|null $compressionMethod Compression method.
  359. *
  360. * Use {@see ZipCompressionMethod::STORED}, {@see
  361. * ZipCompressionMethod::DEFLATED} or
  362. * {@see ZipCompressionMethod::BZIP2}. If null, then auto choosing method.
  363. *
  364. * @throws ZipException
  365. *
  366. * @return ZipFile
  367. */
  368. public function addDir($inputDir, $localPath = '/', $compressionMethod = null);
  369. /**
  370. * Add recursive directory to the zip archive.
  371. *
  372. * @param string $inputDir Input directory
  373. * @param string $localPath add files to this directory, or the root
  374. * @param int|null $compressionMethod Compression method.
  375. * Use {@see ZipCompressionMethod::STORED}, {@see
  376. * ZipCompressionMethod::DEFLATED} or
  377. * {@see ZipCompressionMethod::BZIP2}. If null, then auto choosing method.
  378. *
  379. * @throws ZipException
  380. *
  381. * @return ZipFile
  382. *
  383. * @see ZipCompressionMethod::STORED
  384. * @see ZipCompressionMethod::DEFLATED
  385. * @see ZipCompressionMethod::BZIP2
  386. */
  387. public function addDirRecursive($inputDir, $localPath = '/', $compressionMethod = null);
  388. /**
  389. * Add directories from directory iterator.
  390. *
  391. * @param \Iterator $iterator directory iterator
  392. * @param string $localPath add files to this directory, or the root
  393. * @param int|null $compressionMethod Compression method.
  394. * Use {@see ZipCompressionMethod::STORED}, {@see
  395. * ZipCompressionMethod::DEFLATED} or
  396. * {@see ZipCompressionMethod::BZIP2}. If null, then auto choosing method.
  397. *
  398. * @throws ZipException
  399. *
  400. * @return ZipFile
  401. *
  402. * @see ZipCompressionMethod::STORED
  403. * @see ZipCompressionMethod::DEFLATED
  404. * @see ZipCompressionMethod::BZIP2
  405. */
  406. public function addFilesFromIterator(\Iterator $iterator, $localPath = '/', $compressionMethod = null);
  407. /**
  408. * Add files from glob pattern.
  409. *
  410. * @param string $inputDir Input directory
  411. * @param string $globPattern glob pattern
  412. * @param string $localPath add files to this directory, or the root
  413. * @param int|null $compressionMethod Compression method.
  414. * Use {@see ZipCompressionMethod::STORED},
  415. * {@see ZipCompressionMethod::DEFLATED} or
  416. * {@see ZipCompressionMethod::BZIP2}. If null, then auto choosing method.
  417. *
  418. * @throws ZipException
  419. *
  420. * @return ZipFile
  421. * @sse https://en.wikipedia.org/wiki/Glob_(programming) Glob pattern syntax
  422. */
  423. public function addFilesFromGlob($inputDir, $globPattern, $localPath = '/', $compressionMethod = null);
  424. /**
  425. * Add files recursively from glob pattern.
  426. *
  427. * @param string $inputDir Input directory
  428. * @param string $globPattern glob pattern
  429. * @param string $localPath add files to this directory, or the root
  430. * @param int|null $compressionMethod Compression method.
  431. * Use {@see ZipCompressionMethod::STORED},
  432. * {@see ZipCompressionMethod::DEFLATED} or
  433. * {@see ZipCompressionMethod::BZIP2}. If null, then auto choosing method.
  434. *
  435. * @throws ZipException
  436. *
  437. * @return ZipFile
  438. * @sse https://en.wikipedia.org/wiki/Glob_(programming) Glob pattern syntax
  439. */
  440. public function addFilesFromGlobRecursive($inputDir, $globPattern, $localPath = '/', $compressionMethod = null);
  441. /**
  442. * Add files from regex pattern.
  443. *
  444. * @param string $inputDir search files in this directory
  445. * @param string $regexPattern regex pattern
  446. * @param string $localPath add files to this directory, or the root
  447. * @param int|null $compressionMethod Compression method.
  448. * Use {@see ZipCompressionMethod::STORED},
  449. * {@see ZipCompressionMethod::DEFLATED} or
  450. * {@see ZipCompressionMethod::BZIP2}. If null, then auto choosing method.
  451. *
  452. * @throws ZipException
  453. *
  454. * @return ZipFile
  455. *
  456. * @internal param bool $recursive Recursive search
  457. */
  458. public function addFilesFromRegex($inputDir, $regexPattern, $localPath = '/', $compressionMethod = null);
  459. /**
  460. * Add files recursively from regex pattern.
  461. *
  462. * @param string $inputDir search files in this directory
  463. * @param string $regexPattern regex pattern
  464. * @param string $localPath add files to this directory, or the root
  465. * @param int|null $compressionMethod Compression method.
  466. * Use {@see ZipCompressionMethod::STORED},
  467. * {@see ZipCompressionMethod::DEFLATED} or
  468. * {@see ZipCompressionMethod::BZIP2}. If null, then auto choosing method.
  469. *
  470. * @throws ZipException
  471. *
  472. * @return ZipFile
  473. *
  474. * @internal param bool $recursive Recursive search
  475. */
  476. public function addFilesFromRegexRecursive($inputDir, $regexPattern, $localPath = '/', $compressionMethod = null);
  477. /**
  478. * Add array data to archive.
  479. * Keys is local names.
  480. * Values is contents.
  481. *
  482. * @param array $mapData associative array for added to zip
  483. */
  484. public function addAll(array $mapData);
  485. /**
  486. * Rename the entry.
  487. *
  488. * @param string $oldName old entry name
  489. * @param string $newName new entry name
  490. *
  491. * @throws ZipException
  492. *
  493. * @return ZipFile
  494. */
  495. public function rename($oldName, $newName);
  496. /**
  497. * Delete entry by name.
  498. *
  499. * @param string $entryName zip Entry name
  500. *
  501. * @throws ZipEntryNotFoundException if entry not found
  502. *
  503. * @return ZipFile
  504. */
  505. public function deleteFromName($entryName);
  506. /**
  507. * Delete entries by glob pattern.
  508. *
  509. * @param string $globPattern Glob pattern
  510. *
  511. * @return ZipFile
  512. * @sse https://en.wikipedia.org/wiki/Glob_(programming) Glob pattern syntax
  513. */
  514. public function deleteFromGlob($globPattern);
  515. /**
  516. * Delete entries by regex pattern.
  517. *
  518. * @param string $regexPattern Regex pattern
  519. *
  520. * @return ZipFile
  521. */
  522. public function deleteFromRegex($regexPattern);
  523. /**
  524. * Delete all entries.
  525. *
  526. * @return ZipFile
  527. */
  528. public function deleteAll();
  529. /**
  530. * Set compression level for new entries.
  531. *
  532. * @param int $compressionLevel
  533. *
  534. * @return ZipFile
  535. *
  536. * @see ZipCompressionLevel::NORMAL
  537. * @see ZipCompressionLevel::SUPER_FAST
  538. * @see ZipCompressionLevel::FAST
  539. * @see ZipCompressionLevel::MAXIMUM
  540. */
  541. public function setCompressionLevel($compressionLevel = ZipCompressionLevel::NORMAL);
  542. /**
  543. * @param string $entryName
  544. * @param int $compressionLevel
  545. *
  546. * @throws ZipException
  547. *
  548. * @return ZipFile
  549. *
  550. * @see ZipCompressionLevel::NORMAL
  551. * @see ZipCompressionLevel::SUPER_FAST
  552. * @see ZipCompressionLevel::FAST
  553. * @see ZipCompressionLevel::MAXIMUM
  554. */
  555. public function setCompressionLevelEntry($entryName, $compressionLevel);
  556. /**
  557. * @param string $entryName
  558. * @param int $compressionMethod Compression method.
  559. * Use {@see ZipCompressionMethod::STORED}, {@see ZipCompressionMethod::DEFLATED}
  560. * or
  561. * {@see ZipCompressionMethod::BZIP2}. If null, then auto choosing method.
  562. *
  563. * @throws ZipException
  564. *
  565. * @return ZipFile
  566. *
  567. * @see ZipCompressionMethod::STORED
  568. * @see ZipCompressionMethod::DEFLATED
  569. * @see ZipCompressionMethod::BZIP2
  570. */
  571. public function setCompressionMethodEntry($entryName, $compressionMethod);
  572. /**
  573. * zipalign is optimization to Android application (APK) files.
  574. *
  575. * @param int|null $align
  576. *
  577. * @return ZipFile
  578. *
  579. * @see https://developer.android.com/studio/command-line/zipalign.html
  580. */
  581. public function setZipAlign($align = null);
  582. /**
  583. * Set password to all input encrypted entries.
  584. *
  585. * @param string $password Password
  586. *
  587. * @return ZipFile
  588. */
  589. public function setReadPassword($password);
  590. /**
  591. * Set password to concrete input entry.
  592. *
  593. * @param string $entryName
  594. * @param string $password Password
  595. *
  596. * @throws ZipException
  597. *
  598. * @return ZipFile
  599. */
  600. public function setReadPasswordEntry($entryName, $password);
  601. /**
  602. * Sets a new password for all files in the archive.
  603. *
  604. * @param string $password Password
  605. * @param int|null $encryptionMethod Encryption method
  606. *
  607. * @return ZipFile
  608. */
  609. public function setPassword($password, $encryptionMethod = ZipEncryptionMethod::WINZIP_AES_256);
  610. /**
  611. * Sets a new password of an entry defined by its name.
  612. *
  613. * @param string $entryName
  614. * @param string $password
  615. * @param int|null $encryptionMethod
  616. *
  617. * @throws ZipException
  618. *
  619. * @return ZipFile
  620. */
  621. public function setPasswordEntry($entryName, $password, $encryptionMethod = null);
  622. /**
  623. * Disable encryption for all entries that are already in the archive.
  624. *
  625. * @return ZipFile
  626. */
  627. public function disableEncryption();
  628. /**
  629. * Disable encryption of an entry defined by its name.
  630. *
  631. * @param string $entryName
  632. *
  633. * @return ZipFile
  634. */
  635. public function disableEncryptionEntry($entryName);
  636. /**
  637. * Undo all changes done in the archive.
  638. *
  639. * @return ZipFile
  640. */
  641. public function unchangeAll();
  642. /**
  643. * Undo change archive comment.
  644. *
  645. * @return ZipFile
  646. */
  647. public function unchangeArchiveComment();
  648. /**
  649. * Revert all changes done to an entry with the given name.
  650. *
  651. * @param string|ZipEntry $entry Entry name or ZipEntry
  652. *
  653. * @return ZipFile
  654. */
  655. public function unchangeEntry($entry);
  656. /**
  657. * Save as file.
  658. *
  659. * @param string $filename Output filename
  660. *
  661. * @throws ZipException
  662. *
  663. * @return ZipFile
  664. */
  665. public function saveAsFile($filename);
  666. /**
  667. * Save as stream.
  668. *
  669. * @param resource $handle Output stream resource
  670. *
  671. * @throws ZipException
  672. *
  673. * @return ZipFile
  674. */
  675. public function saveAsStream($handle);
  676. /**
  677. * Output .ZIP archive as attachment.
  678. * Die after output.
  679. *
  680. * @param string $outputFilename Output filename
  681. * @param string|null $mimeType Mime-Type
  682. * @param bool $attachment Http Header 'Content-Disposition' if true then attachment otherwise inline
  683. *
  684. * @throws ZipException
  685. */
  686. public function outputAsAttachment($outputFilename, $mimeType = null, $attachment = true);
  687. /**
  688. * Output .ZIP archive as PSR-7 Response.
  689. *
  690. * @param ResponseInterface $response Instance PSR-7 Response
  691. * @param string $outputFilename Output filename
  692. * @param string|null $mimeType Mime-Type
  693. * @param bool $attachment Http Header 'Content-Disposition' if true then attachment otherwise inline
  694. *
  695. * @throws ZipException
  696. *
  697. * @return ResponseInterface
  698. */
  699. public function outputAsResponse(
  700. ResponseInterface $response,
  701. $outputFilename,
  702. $mimeType = null,
  703. $attachment = true
  704. );
  705. /**
  706. * Returns the zip archive as a string.
  707. *
  708. * @throws ZipException
  709. *
  710. * @return string
  711. */
  712. public function outputAsString();
  713. /**
  714. * Close zip archive and release input stream.
  715. */
  716. public function close();
  717. /**
  718. * Save and reopen zip archive.
  719. *
  720. * @throws ZipException
  721. *
  722. * @return ZipFile
  723. */
  724. public function rewrite();
  725. /**
  726. * Offset to set.
  727. *
  728. * @see http://php.net/manual/en/arrayaccess.offsetset.php
  729. *
  730. * @param string $entryName the offset to assign the value to
  731. * @param string|\DirectoryIterator|\SplFileInfo|resource $contents the value to set
  732. *
  733. * @throws ZipException
  734. *
  735. * @see ZipFile::addFromString
  736. * @see ZipFile::addEmptyDir
  737. * @see ZipFile::addFile
  738. * @see ZipFile::addFilesFromIterator
  739. */
  740. public function offsetSet($entryName, $contents);
  741. /**
  742. * Offset to unset.
  743. *
  744. * @see http://php.net/manual/en/arrayaccess.offsetunset.php
  745. *
  746. * @param string $entryName the offset to unset
  747. *
  748. * @throws ZipEntryNotFoundException
  749. */
  750. public function offsetUnset($entryName);
  751. /**
  752. * Return the current element.
  753. *
  754. * @see http://php.net/manual/en/iterator.current.php
  755. *
  756. * @throws ZipException
  757. *
  758. * @return mixed can return any type
  759. *
  760. * @since 5.0.0
  761. */
  762. public function current();
  763. /**
  764. * Offset to retrieve.
  765. *
  766. * @see http://php.net/manual/en/arrayaccess.offsetget.php
  767. *
  768. * @param string $entryName the offset to retrieve
  769. *
  770. * @throws ZipException
  771. *
  772. * @return string|null
  773. */
  774. public function offsetGet($entryName);
  775. /**
  776. * Return the key of the current element.
  777. *
  778. * @see http://php.net/manual/en/iterator.key.php
  779. *
  780. * @return mixed scalar on success, or null on failure
  781. *
  782. * @since 5.0.0
  783. */
  784. public function key();
  785. /**
  786. * Move forward to next element.
  787. *
  788. * @see http://php.net/manual/en/iterator.next.php
  789. * @since 5.0.0
  790. */
  791. public function next();
  792. /**
  793. * Checks if current position is valid.
  794. *
  795. * @see http://php.net/manual/en/iterator.valid.php
  796. *
  797. * @return bool The return value will be casted to boolean and then evaluated.
  798. * Returns true on success or false on failure.
  799. *
  800. * @since 5.0.0
  801. */
  802. public function valid();
  803. /**
  804. * Whether a offset exists.
  805. *
  806. * @see http://php.net/manual/en/arrayaccess.offsetexists.php
  807. *
  808. * @param string $entryName an offset to check for
  809. *
  810. * @return bool true on success or false on failure.
  811. * The return value will be casted to boolean if non-boolean was returned.
  812. */
  813. public function offsetExists($entryName);
  814. /**
  815. * Rewind the Iterator to the first element.
  816. *
  817. * @see http://php.net/manual/en/iterator.rewind.php
  818. * @since 5.0.0
  819. */
  820. public function rewind();
  821. }