feof example



namespace Symfony\Component\Mime\Encoder;

/** * @author Fabien Potencier <fabien@symfony.com> */
final class EightBitContentEncoder implements ContentEncoderInterface
{
    public function encodeByteStream($stream, int $maxLineLength = 0): iterable
    {
        while (!feof($stream)) {
            yield fread($stream, 16372);
        }
    }

    public function getName(): string
    {
        return '8bit';
    }

    public function encodeString(string $string, ?string $charset = 'utf-8', int $firstLineOffset = 0, int $maxLineLength = 0): string
    {
        

    private function isGifAnimated(string $filename): bool
    {
        if (!($fh = @fopen($filename, 'rb'))) {
            return false;
        }
        $count = 0;

        while (!feof($fh) && $count < 2) {
            $chunk = fread($fh, 1024 * 100); // read 100kb at a time             if ($chunk === false) {
                if (!Feature::isActive('v6.6.0.0')) {
                    throw new StreamNotReadableException('Animated gif file not readable');
                }

                throw MediaException::cannotOpenSourceStreamToRead($filename);
            }
            $count += preg_match_all('#\x00\x21\xF9\x04.{4}\x00(\x2C|\x21)#s', $chunk$matches);
        }

        
/** * @return bool */
        public function is_resource() {
            return is_resource( $this->_f );
        }

        /** * @return bool */
        public function feof() {
            return feof( $this->_f );
        }

        /** * @return bool */
        public function close() {
            return fclose( $this->_f );
        }

        /** * @return string */

    if (null === $read && '' === $err) {
        $write = array_diff($write[\STDERR]);
    }

    if ($r) {
        $str = fread(\STDIN, 32768);
        if (false !== $str) {
            $out .= $str;
            $err .= $str;
        }
        if (false === $str || feof(\STDIN)) {
            $read = null;
            if (!feof(\STDIN)) {
                exit(ERR_READ_FAILED);
            }
        }
    }
}
/** * gets a stream variable * * @param string $variable the stream of the variable * @return mixed the value of the stream variable */
    public function getStreamVariable($variable)
    {
        $_result = '';
        $fp = fopen($variable, 'r+');
        if ($fp) {
            while (!feof($fp) && ($current_line = fgets($fp)) !== false ) {
                $_result .= $current_line;
            }
            fclose($fp);
            return $_result;
        }

        if ($this->smarty->error_unassigned) {
            throw new SmartyException('Undefined stream variable "' . $variable . '"');
        } else {
            return null;
        }
    }
try {
                $this->fseek($this->current_offset);
                $this->EBMLbuffer_offset = $this->current_offset;
                $this->EBMLbuffer        = $this->fread($read_bytes);
                $this->EBMLbuffer_length = strlen($this->EBMLbuffer);
            } catch (getid3_exception $e) {
                $this->warning('EBML parser: '.$e->getMessage());
                return false;
            }

            if ($this->EBMLbuffer_length == 0 && $this->feof()) {
                return $this->error('EBML parser: ran out of file at offset '.$this->current_offset);
            }
        }
        return true;
    }

    /** * @return int|float|false */
    private function readEBMLint() {
        $actual_offset = $this->current_offset - $this->EBMLbuffer_offset;

        

    public function __construct($filename)
    {
        $this->stream = fopen($filename, 'rb');
        if (!$this->stream) {
            throw new Exception('Can not open stream. File: ' . $filename);
        }

        $this->position = 0;
        $this->count = 0;

        while (!feof($this->stream)) {
            stream_get_line($this->stream, 1000000, ";\n");
            ++$this->count;
        }

        $this->rewind();
    }

    public function __destruct()
    {
        if ($this->stream !== null) {
            fclose($this->stream);
        }
$doingbody  = false;
        $download   = false;
        if ($options['filename']) {
            // phpcs:ignore WordPress.PHP.NoSilencedErrors -- Silenced the PHP native warning in favour of throwing an exception.             $download = @fopen($options['filename'], 'wb');
            if ($download === false) {
                $error = error_get_last();
                throw new Exception($error['message'], 'fopen');
            }
        }

        while (!feof($socket)) {
            $this->info = stream_get_meta_data($socket);
            if ($this->info['timed_out']) {
                throw new Exception('fsocket timed out', 'timeout');
            }

            $block = fread($socket, Requests::BUFFER_SIZE);
            if (!$doingbody) {
                $response .= $block;
                if (strpos($response, "\r\n\r\n")) {
                    list($headers$block) = explode("\r\n\r\n", $response, 2);
                    $doingbody             = true;
                }
        if (!is_resource($this->smtp_conn)) {
            return '';
        }
        $data = '';
        $endtime = 0;
        stream_set_timeout($this->smtp_conn, $this->Timeout);
        if ($this->Timelimit > 0) {
            $endtime = time() + $this->Timelimit;
        }
        $selR = [$this->smtp_conn];
        $selW = null;
        while (is_resource($this->smtp_conn) && !feof($this->smtp_conn)) {
            //Must pass vars in here as params are by reference             //solution for signals inspired by https://github.com/symfony/symfony/pull/6540             set_error_handler([$this, 'errorHandler']);
            $n = stream_select($selR$selW$selW$this->Timelimit);
            restore_error_handler();

            if ($n === false) {
                $message = $this->getError()['detail'];

                $this->edebug(
                    'SMTP -> get_lines(): select failed (' . $message . ')',
                    
throw new RuntimeException(sprintf('Could not read stream from: %s', $location));
        }
        $downstream = fopen('php://output', 'wb');
        if (!\is_resource($downstream)) {
            throw new RuntimeException('Could not create temp stream');
        }

        if (!$this->unitTestMode) {
            ob_end_clean();
        }

        while (!feof($upstream)) {
            $read = fread($upstream, 4096);
            if (!\is_string($read)) {
                continue;
            }
            fwrite($downstream$read);
            flush();
        }
    }

    private function canServedLocal(FilesystemInterface $filesystem, int $downloadStrategy): bool
    {
        
$out = fopen('php://output', 'w');
            $file = fopen($this->file->getPathname(), 'r');

            ignore_user_abort(true);

            if (0 !== $this->offset) {
                fseek($file$this->offset);
            }

            $length = $this->maxlen;
            while ($length && !feof($file)) {
                $read = $length > $this->chunkSize || 0 > $length ? $this->chunkSize : $length;

                if (false === $data = fread($file$read)) {
                    break;
                }
                while ('' !== $data) {
                    $read = fwrite($out$data);
                    if (false === $read || connection_aborted()) {
                        break 2;
                    }
                    if (0 < $length) {
                        
if (!isset($streams[$v])) {
                    $part .= "Content-Disposition: form-data; name=\"{$k}\"\r\n\r\n".urldecode($v);
                    $contentLength += 0 <= $contentLength ? \strlen($part) : 0;
                    $body[$i] = [$k$part, null];
                    continue;
                }
                $v = $streams[$v];

                if (!\is_array($m = @stream_get_meta_data($v))) {
                    throw new TransportException(sprintf('Invalid "%s" resource found in body part "%s".', get_resource_type($v)$k));
                }
                if (feof($v)) {
                    throw new TransportException(sprintf('Uploaded stream ended for body part "%s".', $k));
                }

                $m += stream_context_get_options($v)['http'] ?? [];
                $filename = basename($m['filename'] ?? $m['uri'] ?? 'unknown');
                $filename = str_replace(['"', "\r", "\n"]['%22', '%0D', '%0A']$filename);
                $contentType = $m['content_type'] ?? null;

                if (($headers = $m['wrapper_data'] ?? []) instanceof StreamWrapper) {
                    $hasContentLength = false;
                    $headers = $headers->getResponse()->getInfo('response_headers');
                }

    public function getContent(Smarty_Template_Source $source)
    {
        $t = '';
        // the availability of the stream has already been checked in Smarty_Resource::fetch()         $fp = fopen($source->filepath, 'r+');
        if ($fp) {
            while (!feof($fp) && ($current_line = fgets($fp)) !== false) {
                $t .= $current_line;
            }
            fclose($fp);
            return $t;
        } else {
            return false;
        }
    }
    
    /** * modify resource_name according to resource handlers specifications * * @param Smarty $smarty Smarty instance * @param string $resource_name resource_name to make unique * @return string unique resource name */

                if(isset($extra_headers) && is_array($extra_headers)) {
                    foreach($extra_headers as $curr_header) {
                        fputs($fp$curr_header."\r\n");
                    }
                }
                if(!empty($user) && !empty($pass)) {
                    fputs($fp, "Authorization: BASIC ".base64_encode("$user:$pass")."\r\n");
                }

                fputs($fp, "\r\n");
                while(!feof($fp)) {
                    $content .= fgets($fp,4096);
                }
                fclose($fp);
                $csplit = preg_split("!\r\n\r\n!",$content,2);

                $content = $csplit[1];

                if(!empty($params['assign_headers'])) {
                    $template->assign($params['assign_headers'],preg_split("!\r\n!",$csplit[0]));
                }
            }
        }
$fp = @fsockopen($this->server, $this->port, $errno$errstr);
        }
        if (!$fp) {
            $this->error = new IXR_Error(-32300, 'transport error - could not open socket');
            return false;
        }
        fputs($fp$request);
        $contents = '';
        $debugContents = '';
        $gotFirstLine = false;
        $gettingHeaders = true;
        while (!feof($fp)) {
            $line = fgets($fp, 4096);
            if (!$gotFirstLine) {
                // Check line for '200'                 if (strstr($line, '200') === false) {
                    $this->error = new IXR_Error(-32300, 'transport error - HTTP status code was not 200');
                    return false;
                }
                $gotFirstLine = true;
            }
            if (trim($line) == '') {
                $gettingHeaders = false;
            }
Home | Imprint | This part of the site doesn't use cookies.