public function writeBytes(string $buf, int $num = null): int
    {
        $bufSize = Binary::safeStrlen($buf);
        if (!\is_int($num) || $num > $bufSize) {
            $num = $bufSize;
        }
        // @codeCoverageIgnoreStart
        if ($num < 0) {
            throw new CannotPerformOperation('num < 0');
        }
        // @codeCoverageIgnoreEnd
        $remaining = $num;
        do {
            // @codeCoverageIgnoreStart
            if ($remaining <= 0) {
                break;
            }
            // @codeCoverageIgnoreEnd
            $written = \fwrite($this->fp, $buf, $remaining);
            if ($written === false) {
                // @codeCoverageIgnoreStart
                throw new FileAccessDenied(
                    'Could not write to the file'
                );
                // @codeCoverageIgnoreEnd
            }
            $buf = Binary::safeSubstr($buf, $written, null);
            $this->pos += $written;
            $this->stat = \fstat($this->fp);
            $remaining -= $written;
        } while ($remaining > 0);
        return $num;
    }
public function writeBytes(string $buf, int $num = null): int
    {
        $bufSize = Binary::safeStrlen($buf);
        if (!\is_int($num) || $num > $bufSize) {
            $num = $bufSize;
        }
        // @codeCoverageIgnoreStart
        if ($num < 0) {
            throw new CannotPerformOperation('num < 0');
        }
        // @codeCoverageIgnoreEnd
        $remaining = $num;
        do {
            // @codeCoverageIgnoreStart
            if ($remaining <= 0) {
                break;
            }
            // @codeCoverageIgnoreEnd
            $written = \fwrite($this->fp, $buf, $remaining);
            if ($written === false) {
                // @codeCoverageIgnoreStart
                throw new FileAccessDenied(
                    'Could not write to the file'
                );
                // @codeCoverageIgnoreEnd
            }
            $buf = Binary::safeSubstr($buf, $written, null);
            $this->pos += $written;
            $this->stat = \fstat($this->fp);
            $remaining -= $written;
        } while ($remaining > 0);
        return $num;
    }
public function writeBytes ( string $ buf , int $ num = null ) : int { $ bufSize = Binary :: safeStrlen ( $ buf ) ; if ( ! \ is_int ( $ num ) || $ num > $ bufSize ) { $ num = $ bufSize ; } // @codeCoverageIgnoreStart if ( $ num < 0 ) { throw new CannotPerformOperation ( 'num < 0' ) ; } // @codeCoverageIgnoreEnd $ remaining = $ num ; do { // @codeCoverageIgnoreStart if ( $ remaining <= 0 ) { break ; } // @codeCoverageIgnoreEnd $ written = \ fwrite ( $ this -> fp , $ buf , $ remaining ) ; if ( $ written === false ) { // @codeCoverageIgnoreStart throw new FileAccessDenied ( 'Could not write to the file' ) ; // @codeCoverageIgnoreEnd } $ buf = Binary :: safeSubstr ( $ buf , $ written , null ) ; $ this -> pos += $ written ; $ this -> stat = \ fstat ( $ this -> fp ) ; $ remaining -= $ written ; } while ( $ remaining > 0 ) ; return $ num ; }
Write to a stream; prevent partial writes

@param string $buf
@param int|null $num (number of bytes)
@return int

@throws CannotPerformOperation
@throws FileAccessDenied
@throws \TypeError
Write to a stream ; prevent partial writes