. * * @author Julien Fontanet * @license http://www.gnu.org/licenses/gpl-3.0-standalone.html GPLv3 * * @package Xen Orchestra Server */ /** * */ final class BufferedWriter { /** * @param string $data */ function __construct($data, $len = null) { $this->_data = $data; $this->_len = $len ?: strlen($data); } /** * */ function onWrite($handle) { $written = @fwrite( $handle, $this->_data, $this->_len ); if ($written === false) { // @todo Log error. return false; } $this->_len -= $written; if (!$this->_len) { // Write complete, stops watching this handle. return false; } $this->_data = substr($this->_data, -$this->_len); } }