PHPDaemon\FS\File::write PHP Method

write() public method

Writes data to file
public write ( string $data, callable $cb = null, integer $offset = null, integer $pri = EIO_PRI_DEFAULT ) : resource | false
$data string Data
$cb callable Callback
$offset integer Offset
$pri integer Priority
return resource | false
    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;
    }