ZipFileInterface.php 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897
  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 The entries to extract. It accepts either
  264. * a single entry name or an array of names.
  265. *
  266. * @throws ZipException
  267. *
  268. * @return ZipFile
  269. */
  270. public function extractTo($destDir, $entries = null);
  271. /**
  272. * Add entry from the string.
  273. *
  274. * @param string $entryName zip entry name
  275. * @param string $contents string contents
  276. * @param int|null $compressionMethod Compression method.
  277. * Use {@see ZipCompressionMethod::STORED},
  278. * {@see ZipCompressionMethod::DEFLATED} or
  279. * {@see ZipCompressionMethod::BZIP2}.
  280. * If null, then auto choosing method.
  281. *
  282. * @throws ZipException
  283. *
  284. * @return ZipFile
  285. */
  286. public function addFromString($entryName, $contents, $compressionMethod = null);
  287. /**
  288. * @param Finder $finder
  289. * @param array $options
  290. *
  291. * @throws ZipException
  292. *
  293. * @return ZipEntry[]
  294. */
  295. public function addFromFinder(Finder $finder, array $options = []);
  296. /**
  297. * @param \SplFileInfo $file
  298. * @param string|null $entryName
  299. * @param array $options
  300. *
  301. * @throws ZipException
  302. *
  303. * @return ZipEntry
  304. */
  305. public function addSplFile(\SplFileInfo $file, $entryName = null, array $options = []);
  306. /**
  307. * Add entry from the file.
  308. *
  309. * @param string $filename destination file
  310. * @param string|null $entryName zip Entry name
  311. * @param int|null $compressionMethod Compression method.
  312. * Use {@see ZipCompressionMethod::STORED},
  313. * {@see ZipCompressionMethod::DEFLATED} or
  314. * {@see ZipCompressionMethod::BZIP2}.
  315. * If null, then auto choosing method.
  316. *
  317. * @throws ZipException
  318. *
  319. * @return ZipFile
  320. */
  321. public function addFile($filename, $entryName = null, $compressionMethod = null);
  322. /**
  323. * Add entry from the stream.
  324. *
  325. * @param resource $stream stream resource
  326. * @param string $entryName zip Entry name
  327. * @param int|null $compressionMethod Compression method.
  328. * Use {@see ZipCompressionMethod::STORED},
  329. * {@see ZipCompressionMethod::DEFLATED} or
  330. * {@see ZipCompressionMethod::BZIP2}.
  331. * If null, then auto choosing method.
  332. *
  333. * @throws ZipException
  334. *
  335. * @return ZipFile
  336. */
  337. public function addFromStream($stream, $entryName, $compressionMethod = null);
  338. /**
  339. * Add an empty directory in the zip archive.
  340. *
  341. * @param string $dirName
  342. *
  343. * @throws ZipException
  344. *
  345. * @return ZipFile
  346. */
  347. public function addEmptyDir($dirName);
  348. /**
  349. * Add directory not recursively to the zip archive.
  350. *
  351. * @param string $inputDir Input directory
  352. * @param string $localPath add files to this directory, or the root
  353. * @param int|null $compressionMethod Compression method.
  354. *
  355. * Use {@see ZipCompressionMethod::STORED}, {@see
  356. * ZipCompressionMethod::DEFLATED} or
  357. * {@see ZipCompressionMethod::BZIP2}. If null, then auto choosing method.
  358. *
  359. * @throws ZipException
  360. *
  361. * @return ZipFile
  362. */
  363. public function addDir($inputDir, $localPath = '/', $compressionMethod = null);
  364. /**
  365. * Add recursive directory to the zip archive.
  366. *
  367. * @param string $inputDir Input directory
  368. * @param string $localPath add files to this directory, or the root
  369. * @param int|null $compressionMethod Compression method.
  370. * Use {@see ZipCompressionMethod::STORED}, {@see
  371. * ZipCompressionMethod::DEFLATED} or
  372. * {@see ZipCompressionMethod::BZIP2}. If null, then auto choosing method.
  373. *
  374. * @throws ZipException
  375. *
  376. * @return ZipFile
  377. *
  378. * @see ZipCompressionMethod::STORED
  379. * @see ZipCompressionMethod::DEFLATED
  380. * @see ZipCompressionMethod::BZIP2
  381. */
  382. public function addDirRecursive($inputDir, $localPath = '/', $compressionMethod = null);
  383. /**
  384. * Add directories from directory iterator.
  385. *
  386. * @param \Iterator $iterator directory iterator
  387. * @param string $localPath add files to this directory, or the root
  388. * @param int|null $compressionMethod Compression method.
  389. * Use {@see ZipCompressionMethod::STORED}, {@see
  390. * ZipCompressionMethod::DEFLATED} or
  391. * {@see ZipCompressionMethod::BZIP2}. If null, then auto choosing method.
  392. *
  393. * @throws ZipException
  394. *
  395. * @return ZipFile
  396. *
  397. * @see ZipCompressionMethod::STORED
  398. * @see ZipCompressionMethod::DEFLATED
  399. * @see ZipCompressionMethod::BZIP2
  400. */
  401. public function addFilesFromIterator(\Iterator $iterator, $localPath = '/', $compressionMethod = null);
  402. /**
  403. * Add files from glob pattern.
  404. *
  405. * @param string $inputDir Input directory
  406. * @param string $globPattern glob pattern
  407. * @param string $localPath add files to this directory, or the root
  408. * @param int|null $compressionMethod Compression method.
  409. * Use {@see ZipCompressionMethod::STORED},
  410. * {@see ZipCompressionMethod::DEFLATED} or
  411. * {@see ZipCompressionMethod::BZIP2}. If null, then auto choosing method.
  412. *
  413. * @throws ZipException
  414. *
  415. * @return ZipFile
  416. * @sse https://en.wikipedia.org/wiki/Glob_(programming) Glob pattern syntax
  417. */
  418. public function addFilesFromGlob($inputDir, $globPattern, $localPath = '/', $compressionMethod = null);
  419. /**
  420. * Add files recursively from glob pattern.
  421. *
  422. * @param string $inputDir Input directory
  423. * @param string $globPattern glob pattern
  424. * @param string $localPath add files to this directory, or the root
  425. * @param int|null $compressionMethod Compression method.
  426. * Use {@see ZipCompressionMethod::STORED},
  427. * {@see ZipCompressionMethod::DEFLATED} or
  428. * {@see ZipCompressionMethod::BZIP2}. If null, then auto choosing method.
  429. *
  430. * @throws ZipException
  431. *
  432. * @return ZipFile
  433. * @sse https://en.wikipedia.org/wiki/Glob_(programming) Glob pattern syntax
  434. */
  435. public function addFilesFromGlobRecursive($inputDir, $globPattern, $localPath = '/', $compressionMethod = null);
  436. /**
  437. * Add files from regex pattern.
  438. *
  439. * @param string $inputDir search files in this directory
  440. * @param string $regexPattern regex pattern
  441. * @param string $localPath add files to this directory, or the root
  442. * @param int|null $compressionMethod Compression method.
  443. * Use {@see ZipCompressionMethod::STORED},
  444. * {@see ZipCompressionMethod::DEFLATED} or
  445. * {@see ZipCompressionMethod::BZIP2}. If null, then auto choosing method.
  446. *
  447. * @throws ZipException
  448. *
  449. * @return ZipFile
  450. *
  451. * @internal param bool $recursive Recursive search
  452. */
  453. public function addFilesFromRegex($inputDir, $regexPattern, $localPath = '/', $compressionMethod = null);
  454. /**
  455. * Add files recursively from regex pattern.
  456. *
  457. * @param string $inputDir search files in this directory
  458. * @param string $regexPattern regex pattern
  459. * @param string $localPath add files to this directory, or the root
  460. * @param int|null $compressionMethod Compression method.
  461. * Use {@see ZipCompressionMethod::STORED},
  462. * {@see ZipCompressionMethod::DEFLATED} or
  463. * {@see ZipCompressionMethod::BZIP2}. If null, then auto choosing method.
  464. *
  465. * @throws ZipException
  466. *
  467. * @return ZipFile
  468. *
  469. * @internal param bool $recursive Recursive search
  470. */
  471. public function addFilesFromRegexRecursive($inputDir, $regexPattern, $localPath = '/', $compressionMethod = null);
  472. /**
  473. * Add array data to archive.
  474. * Keys is local names.
  475. * Values is contents.
  476. *
  477. * @param array $mapData associative array for added to zip
  478. */
  479. public function addAll(array $mapData);
  480. /**
  481. * Rename the entry.
  482. *
  483. * @param string $oldName old entry name
  484. * @param string $newName new entry name
  485. *
  486. * @throws ZipException
  487. *
  488. * @return ZipFile
  489. */
  490. public function rename($oldName, $newName);
  491. /**
  492. * Delete entry by name.
  493. *
  494. * @param string $entryName zip Entry name
  495. *
  496. * @throws ZipEntryNotFoundException if entry not found
  497. *
  498. * @return ZipFile
  499. */
  500. public function deleteFromName($entryName);
  501. /**
  502. * Delete entries by glob pattern.
  503. *
  504. * @param string $globPattern Glob pattern
  505. *
  506. * @return ZipFile
  507. * @sse https://en.wikipedia.org/wiki/Glob_(programming) Glob pattern syntax
  508. */
  509. public function deleteFromGlob($globPattern);
  510. /**
  511. * Delete entries by regex pattern.
  512. *
  513. * @param string $regexPattern Regex pattern
  514. *
  515. * @return ZipFile
  516. */
  517. public function deleteFromRegex($regexPattern);
  518. /**
  519. * Delete all entries.
  520. *
  521. * @return ZipFile
  522. */
  523. public function deleteAll();
  524. /**
  525. * Set compression level for new entries.
  526. *
  527. * @param int $compressionLevel
  528. *
  529. * @return ZipFile
  530. *
  531. * @see ZipCompressionLevel::NORMAL
  532. * @see ZipCompressionLevel::SUPER_FAST
  533. * @see ZipCompressionLevel::FAST
  534. * @see ZipCompressionLevel::MAXIMUM
  535. */
  536. public function setCompressionLevel($compressionLevel = ZipCompressionLevel::NORMAL);
  537. /**
  538. * @param string $entryName
  539. * @param int $compressionLevel
  540. *
  541. * @throws ZipException
  542. *
  543. * @return ZipFile
  544. *
  545. * @see ZipCompressionLevel::NORMAL
  546. * @see ZipCompressionLevel::SUPER_FAST
  547. * @see ZipCompressionLevel::FAST
  548. * @see ZipCompressionLevel::MAXIMUM
  549. */
  550. public function setCompressionLevelEntry($entryName, $compressionLevel);
  551. /**
  552. * @param string $entryName
  553. * @param int $compressionMethod Compression method.
  554. * Use {@see ZipCompressionMethod::STORED}, {@see ZipCompressionMethod::DEFLATED}
  555. * or
  556. * {@see ZipCompressionMethod::BZIP2}. If null, then auto choosing method.
  557. *
  558. * @throws ZipException
  559. *
  560. * @return ZipFile
  561. *
  562. * @see ZipCompressionMethod::STORED
  563. * @see ZipCompressionMethod::DEFLATED
  564. * @see ZipCompressionMethod::BZIP2
  565. */
  566. public function setCompressionMethodEntry($entryName, $compressionMethod);
  567. /**
  568. * zipalign is optimization to Android application (APK) files.
  569. *
  570. * @param int|null $align
  571. *
  572. * @return ZipFile
  573. *
  574. * @see https://developer.android.com/studio/command-line/zipalign.html
  575. */
  576. public function setZipAlign($align = null);
  577. /**
  578. * Set password to all input encrypted entries.
  579. *
  580. * @param string $password Password
  581. *
  582. * @return ZipFile
  583. */
  584. public function setReadPassword($password);
  585. /**
  586. * Set password to concrete input entry.
  587. *
  588. * @param string $entryName
  589. * @param string $password Password
  590. *
  591. * @throws ZipException
  592. *
  593. * @return ZipFile
  594. */
  595. public function setReadPasswordEntry($entryName, $password);
  596. /**
  597. * Sets a new password for all files in the archive.
  598. *
  599. * @param string $password Password
  600. * @param int|null $encryptionMethod Encryption method
  601. *
  602. * @return ZipFile
  603. */
  604. public function setPassword($password, $encryptionMethod = ZipEncryptionMethod::WINZIP_AES_256);
  605. /**
  606. * Sets a new password of an entry defined by its name.
  607. *
  608. * @param string $entryName
  609. * @param string $password
  610. * @param int|null $encryptionMethod
  611. *
  612. * @throws ZipException
  613. *
  614. * @return ZipFile
  615. */
  616. public function setPasswordEntry($entryName, $password, $encryptionMethod = null);
  617. /**
  618. * Disable encryption for all entries that are already in the archive.
  619. *
  620. * @return ZipFile
  621. */
  622. public function disableEncryption();
  623. /**
  624. * Disable encryption of an entry defined by its name.
  625. *
  626. * @param string $entryName
  627. *
  628. * @return ZipFile
  629. */
  630. public function disableEncryptionEntry($entryName);
  631. /**
  632. * Undo all changes done in the archive.
  633. *
  634. * @return ZipFile
  635. */
  636. public function unchangeAll();
  637. /**
  638. * Undo change archive comment.
  639. *
  640. * @return ZipFile
  641. */
  642. public function unchangeArchiveComment();
  643. /**
  644. * Revert all changes done to an entry with the given name.
  645. *
  646. * @param string|ZipEntry $entry Entry name or ZipEntry
  647. *
  648. * @return ZipFile
  649. */
  650. public function unchangeEntry($entry);
  651. /**
  652. * Save as file.
  653. *
  654. * @param string $filename Output filename
  655. *
  656. * @throws ZipException
  657. *
  658. * @return ZipFile
  659. */
  660. public function saveAsFile($filename);
  661. /**
  662. * Save as stream.
  663. *
  664. * @param resource $handle Output stream resource
  665. *
  666. * @throws ZipException
  667. *
  668. * @return ZipFile
  669. */
  670. public function saveAsStream($handle);
  671. /**
  672. * Output .ZIP archive as attachment.
  673. * Die after output.
  674. *
  675. * @param string $outputFilename Output filename
  676. * @param string|null $mimeType Mime-Type
  677. * @param bool $attachment Http Header 'Content-Disposition' if true then attachment otherwise inline
  678. *
  679. * @throws ZipException
  680. */
  681. public function outputAsAttachment($outputFilename, $mimeType = null, $attachment = true);
  682. /**
  683. * Output .ZIP archive as PSR-7 Response.
  684. *
  685. * @param ResponseInterface $response Instance PSR-7 Response
  686. * @param string $outputFilename Output filename
  687. * @param string|null $mimeType Mime-Type
  688. * @param bool $attachment Http Header 'Content-Disposition' if true then attachment otherwise inline
  689. *
  690. * @throws ZipException
  691. *
  692. * @return ResponseInterface
  693. */
  694. public function outputAsResponse(
  695. ResponseInterface $response,
  696. $outputFilename,
  697. $mimeType = null,
  698. $attachment = true
  699. );
  700. /**
  701. * Returns the zip archive as a string.
  702. *
  703. * @throws ZipException
  704. *
  705. * @return string
  706. */
  707. public function outputAsString();
  708. /**
  709. * Close zip archive and release input stream.
  710. */
  711. public function close();
  712. /**
  713. * Save and reopen zip archive.
  714. *
  715. * @throws ZipException
  716. *
  717. * @return ZipFile
  718. */
  719. public function rewrite();
  720. /**
  721. * Offset to set.
  722. *
  723. * @see http://php.net/manual/en/arrayaccess.offsetset.php
  724. *
  725. * @param string $entryName the offset to assign the value to
  726. * @param string|\DirectoryIterator|\SplFileInfo|resource $contents the value to set
  727. *
  728. * @throws ZipException
  729. *
  730. * @see ZipFile::addFromString
  731. * @see ZipFile::addEmptyDir
  732. * @see ZipFile::addFile
  733. * @see ZipFile::addFilesFromIterator
  734. */
  735. public function offsetSet($entryName, $contents);
  736. /**
  737. * Offset to unset.
  738. *
  739. * @see http://php.net/manual/en/arrayaccess.offsetunset.php
  740. *
  741. * @param string $entryName the offset to unset
  742. *
  743. * @throws ZipEntryNotFoundException
  744. */
  745. public function offsetUnset($entryName);
  746. /**
  747. * Return the current element.
  748. *
  749. * @see http://php.net/manual/en/iterator.current.php
  750. *
  751. * @throws ZipException
  752. *
  753. * @return mixed can return any type
  754. *
  755. * @since 5.0.0
  756. */
  757. public function current();
  758. /**
  759. * Offset to retrieve.
  760. *
  761. * @see http://php.net/manual/en/arrayaccess.offsetget.php
  762. *
  763. * @param string $entryName the offset to retrieve
  764. *
  765. * @throws ZipException
  766. *
  767. * @return string|null
  768. */
  769. public function offsetGet($entryName);
  770. /**
  771. * Return the key of the current element.
  772. *
  773. * @see http://php.net/manual/en/iterator.key.php
  774. *
  775. * @return mixed scalar on success, or null on failure
  776. *
  777. * @since 5.0.0
  778. */
  779. public function key();
  780. /**
  781. * Move forward to next element.
  782. *
  783. * @see http://php.net/manual/en/iterator.next.php
  784. * @since 5.0.0
  785. */
  786. public function next();
  787. /**
  788. * Checks if current position is valid.
  789. *
  790. * @see http://php.net/manual/en/iterator.valid.php
  791. *
  792. * @return bool The return value will be casted to boolean and then evaluated.
  793. * Returns true on success or false on failure.
  794. *
  795. * @since 5.0.0
  796. */
  797. public function valid();
  798. /**
  799. * Whether a offset exists.
  800. *
  801. * @see http://php.net/manual/en/arrayaccess.offsetexists.php
  802. *
  803. * @param string $entryName an offset to check for
  804. *
  805. * @return bool true on success or false on failure.
  806. * The return value will be casted to boolean if non-boolean was returned.
  807. */
  808. public function offsetExists($entryName);
  809. /**
  810. * Rewind the Iterator to the first element.
  811. *
  812. * @see http://php.net/manual/en/iterator.rewind.php
  813. * @since 5.0.0
  814. */
  815. public function rewind();
  816. }