20000 files -> 1.2MB larger
* xxxxxx
* # F#x#x#x#x#x#x!
*
* @param resource $archiveHandle archive resource
* @param boolean $skipContents if true skip contents
* @param boolean $skipMarker if true skip marker
*
* @return static
*/
public static function readFromArchive($archiveHandle, $skipContents = false, $skipMarker = false)
{
// RSR TODO Read header from archive handle and populate members
// TODO: return null if end of archive or throw exception if can read something but its not a file header
$instance = new static();
if (!$skipMarker) {
$marker = @fread($archiveHandle, 3);
if ($marker === false) {
if (feof($archiveHandle)) {
return false;
} else {
throw new Exception('Error reading file header');
}
}
if ($marker != '') {
throw new Exception("Invalid file header marker found [{$marker}] : location " . ftell($archiveHandle));
}
}
$instance->fileSize = DupArchiveHeaderU::readStandardHeaderField($archiveHandle, 'FS');
$instance->mtime = DupArchiveHeaderU::readStandardHeaderField($archiveHandle, 'MT');
$instance->permissions = DupArchiveHeaderU::readStandardHeaderField($archiveHandle, 'P');
$instance->hash = DupArchiveHeaderU::readStandardHeaderField($archiveHandle, 'HA');
$instance->relativePathLength = DupArchiveHeaderU::readStandardHeaderField($archiveHandle, 'RPL');
// Skip
// fread($archiveHandle, 5);
// Skip the
// fread($archiveHandle, 4);
// Skip the and the
fread($archiveHandle, 9);
if ($skipContents && ($instance->fileSize > 0)) {
$dataSize = 0;
$moreGlobs = true;
while ($moreGlobs) {
$globHeader = DupArchiveReaderGlobHeader::readFromArchive($archiveHandle, true);
$dataSize += $globHeader->originalSize;
$moreGlobs = ($dataSize < $instance->fileSize);
}
}
return $instance;
}
}