public function doSlowCleanUp()
{
for ($i = 0; $i < 1024; ++$i) {
if ($this->locationTable[$i][0] === 0 or $this->locationTable[$i][1] === 0) {
continue;
}
fseek($this->filePointer, $this->locationTable[$i][0] << 12);
$chunk = fread($this->filePointer, $this->locationTable[$i][1] << 12);
$length = Binary::readInt(substr($chunk, 0, 4));
if ($length <= 1) {
$this->locationTable[$i] = [0, 0, 0];
//Non-generated chunk, remove it from index
}
try {
$chunk = zlib_decode(substr($chunk, 5));
} catch (Throwable $e) {
$this->locationTable[$i] = [0, 0, 0];
//Corrupted chunk, remove it
continue;
}
$chunk = chr(self::COMPRESSION_ZLIB) . zlib_encode($chunk, ZLIB_ENCODING_DEFLATE, 9);
$chunk = Binary::writeInt(strlen($chunk)) . $chunk;
$sectors = (int) ceil(strlen($chunk) / 4096);
if ($sectors > $this->locationTable[$i][1]) {
$this->locationTable[$i][0] = $this->lastSector + 1;
$this->lastSector += $sectors;
}
fseek($this->filePointer, $this->locationTable[$i][0] << 12);
fwrite($this->filePointer, str_pad($chunk, $sectors << 12, "", STR_PAD_RIGHT));
}
$this->writeLocationTable();
$n = $this->cleanGarbage();
$this->writeLocationTable();
return $n;
}