You are here

public function LocalStream::stream_read in Drupal 9

Same name and namespace in other branches
  1. 8 core/lib/Drupal/Core/StreamWrapper/LocalStream.php \Drupal\Core\StreamWrapper\LocalStream::stream_read()

Read from stream.

This method is called in response to fread() and fgets().

Note, remember to update the read/write position of the stream (by the number of bytes that were successfully read).

Note, PhpStreamWrapperInterface::stream_eof() is called directly after calling PhpStreamWrapperInterface::stream_read() to check if EOF has been reached. If not implemented, EOF is assumed.

Warning, when reading the whole file (e.g., with file_get_contents()), PHP will call PhpStreamWrapperInterface::stream_read() followed by PhpStreamWrapperInterface::stream_eof() in a loop but as long as PhpStreamWrapperInterface::stream_read() returns a non-empty string, the return value of PhpStreamWrapperInterface::stream_eof() is ignored.

Parameters

int $count: How many bytes of data from the current position should be returned.

Return value

string|false If there are less than $count bytes available, return as many as are available. If no more data is available, return either FALSE or an empty string.

Overrides PhpStreamWrapperInterface::stream_read

See also

fread()

fgets()

http://php.net/manual/en/streamwrapper.stream-read.php

File

core/lib/Drupal/Core/StreamWrapper/LocalStream.php, line 181

Class

LocalStream
Defines a Drupal stream wrapper base class for local files.

Namespace

Drupal\Core\StreamWrapper

Code

public function stream_read($count) {
  return fread($this->handle, $count);
}