public function write($data, $cb = null, $offset = null, $pri = EIO_PRI_DEFAULT)
{
$cb = CallbackWrapper::forceWrap($cb);
if (!$this->fd) {
if ($cb) {
$cb($this, false);
}
return false;
}
if ($data === '') {
if ($cb) {
$cb($this, 0);
}
return false;
}
if (!FileSystem::$supported) {
if ($offset !== null) {
fseek($data, $offset);
}
$r = fwrite($this->fd, $data);
if ($cb) {
$cb($this, $r);
}
return false;
}
if ($cb !== null) {
$this->onWriteOnce->push($cb);
}
$l = mb_orig_strlen($data);
if ($offset === null) {
$offset = $this->offset;
$this->offset += $l;
}
$this->writing = true;
$res = eio_write($this->fd, $data, $l, $offset, $pri, function ($file, $result) {
$this->writing = false;
$this->onWriteOnce->executeAll($file, $result);
}, $this);
return $res;
}