1 file_example_session_streams.inc public FileExampleSessionStreamWrapper::stream_read($count)

Support for fread(), file_get_contents() etc.

Parameters

int $count: Maximum number of bytes to be read.

Return value

string: The string that was read, or FALSE in case of an error.

Overrides StreamWrapperInterface::stream_read

See also

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

File

modules/examples/file_example/file_example_session_streams.inc, line 317
Provides a demonstration session:// stream-wrapper.

Class

FileExampleSessionStreamWrapper
Example stream wrapper class to handle session:// streams.

Code

public function stream_read($count) {
  if (is_string($this->sessionContent)) {
    $remaining_chars = backdrop_strlen($this->sessionContent) - $this->streamPointer;
    $number_to_read = min($count, $remaining_chars);
    if ($remaining_chars > 0) {
      $buffer = backdrop_substr($this->sessionContent, $this->streamPointer, $number_to_read);
      $this->streamPointer += $number_to_read;
      return $buffer;
    }
  }

  return FALSE;
}