Search moodle.org's
Developer Documentation

See Release Notes

  • Bug fixes for general core bugs in 4.0.x will end 8 May 2023 (12 months).
  • Bug fixes for security issues in 4.0.x will end 13 November 2023 (18 months).
  • PHP version: minimum PHP 7.3.0 Note: the minimum PHP version has increased since Moodle 3.10. PHP 7.4.x is also supported.

Differences Between: [Versions 400 and 401] [Versions 400 and 402] [Versions 400 and 403]

(no description)

File Size: 253 lines (7 kb)
Included or required:0 times
Referenced: 0 times
Includes or requires: 0 files

Defines 1 class

Stream:: (16 methods):
  __construct()
  close()
  detach()
  __toString()
  seek()
  isSeekable()
  getMetadata()
  getSize()
  tell()
  eof()
  rewind()
  write()
  isWritable()
  read()
  isReadable()
  getContents()


Class: Stream  - X-Ref

Describes a data stream.

Typically, an instance will wrap a PHP stream; this interface provides
a wrapper around the most common operations, including serialization of
the entire stream to a string.
__construct($stream)   X-Ref
No description

close()   X-Ref
Closes the stream and any underlying resources.

return: void

detach()   X-Ref
Separates any underlying resources from the stream.

After the stream has been detached, the stream is in an unusable state.

return: resource|null Underlying PHP stream, if any

__toString()   X-Ref
Reads all data from the stream into a string, from the beginning to end.

This method MUST attempt to seek to the beginning of the stream before
reading data and read the stream until the end is reached.

Warning: This could attempt to load a large amount of data into memory.

This method MUST NOT raise an exception in order to conform with PHP's
string casting operations.

return: string

seek($offset, $whence = SEEK_SET)   X-Ref
Seek to a position in the stream.

param: int $offset Stream offset
param: int $whence Specifies how the cursor position will be calculated

isSeekable()   X-Ref
Returns whether or not the stream is seekable.

return: bool

getMetadata($key = null)   X-Ref
Get stream metadata as an associative array or retrieve a specific key.

The keys returned are identical to the keys returned from PHP's
stream_get_meta_data() function.

return: array|mixed|null Returns an associative array if no key is
param: string $key Specific metadata to retrieve.

getSize()   X-Ref
Get the size of the stream if known.

return: int|null Returns the size in bytes if known, or null if unknown.

tell()   X-Ref
Returns the current position of the file read/write pointer

return: int Position of the file pointer

eof()   X-Ref
Returns true if the stream is at the end of the stream.

return: bool

rewind()   X-Ref
Seek to the beginning of the stream.

If the stream is not seekable, this method will raise an exception;
otherwise, it will perform a seek(0).


write($string)   X-Ref
Write data to the stream.

return: int Returns the number of bytes written to the stream.
param: string $string The string that is to be written.

isWritable()   X-Ref
Returns whether or not the stream is writable.

return: bool

read($length)   X-Ref
Read data from the stream.

return: string Returns the data read from the stream, or an empty string
param: int $length Read up to $length bytes from the object and return

isReadable()   X-Ref
Returns whether or not the stream is readable.

return: bool

getContents()   X-Ref
Returns the remaining contents in a string

return: string