Created
October 27, 2011 16:23
-
-
Save stealth35/1320041 to your computer and use it in GitHub Desktop.
ZipArchiveIterator
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
class ZipArchiveIterator implements \Iterator, \SeekableIterator, \Countable | |
{ | |
private $current; | |
private $position; | |
private $zip; | |
public function __construct($file_name) | |
{ | |
$this->zip = new \ZipArchive(); | |
$this->zip->open($file_name); | |
$this->seek(0); | |
} | |
public function current() | |
{ | |
return $this->current; | |
} | |
public function key() | |
{ | |
return $this->position; | |
} | |
public function next() | |
{ | |
$this->seek(++$this->position); | |
} | |
public function rewind() | |
{ | |
$this->seek(0); | |
} | |
public function valid() | |
{ | |
return $this->current; | |
} | |
public function seek($position) | |
{ | |
$this->position = $position; | |
$this->current = $this->zip->statIndex($position); | |
} | |
public function count() | |
{ | |
return $this->zip->numFiles; | |
} | |
public function __toString() | |
{ | |
return $this->current['name']; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment