public function endTag()
{
$stackelem = array_pop($this->_stack);
if ($stackelem['sent']) {
$this->_endTag();
if (count($this->_stack) == 0 && $this->multipart) {
$this->_stream->rewind();
$len = $this->_stream->length();
$totalCount = count($this->_parts) + 1;
$header = pack('i', $totalCount);
$offset = $totalCount * 2 * 4 + 4;
$header .= pack('ii', $offset, $len);
$offset += $len;
// start/length of parts
foreach ($this->_parts as $bp) {
if (is_resource($bp)) {
rewind($bp);
$stat = fstat($bp);
$len = $stat['size'];
} else {
$len = strlen(bin2hex($bp)) / 2;
}
$header .= pack('ii', $offset, $len);
$offset += $len;
}
// Output
$this->_tempStream->add($header);
$this->_stream->rewind();
$this->_tempStream->add($this->_stream);
foreach ($this->_parts as $bp) {
if (is_resource($bp)) {
rewind($bp);
$this->_tempStream->add($bp);
fclose($bp);
} else {
$this->_tempStream->add($bp);
}
}
$this->_stream->close();
$this->_stream = $this->_tempStream;
}
}
}