Skip to content

Instantly share code, notes, and snippets.

@stealth35
Created October 27, 2011 16:23
Show Gist options
  • Save stealth35/1320041 to your computer and use it in GitHub Desktop.
Save stealth35/1320041 to your computer and use it in GitHub Desktop.
ZipArchiveIterator
<?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