Search moodle.org's
Developer Documentation

See Release Notes

  • Bug fixes for general core bugs in 4.3.x will end 7 October 2024 (12 months).
  • Bug fixes for security issues in 4.3.x will end 21 April 2025 (18 months).
  • PHP version: minimum PHP 8.0.0 Note: minimum PHP version has increased since Moodle 4.1. PHP 8.2.x is supported too.

Differences Between: [Versions 310 and 403] [Versions 39 and 403]

This file is part of FPDI

Copyright: Copyright (c) 2020 Setasign GmbH & Co. KG (https://www.setasign.com)
License: http://opensource.org/licenses/mit-license The MIT License
File Size: 471 lines (12 kb)
Included or required:0 times
Referenced: 0 times
Includes or requires: 0 files

Defines 1 class

StreamReader:: (21 methods):
  createByString()
  createByFile()
  __construct()
  __destruct()
  cleanUp()
  getBufferLength()
  getPosition()
  getBuffer()
  getByte()
  readByte()
  readBytes()
  readLine()
  setOffset()
  getOffset()
  addOffset()
  ensureContent()
  getStream()
  getTotalLength()
  reset()
  ensure()
  increaseLength()


Class: StreamReader  - X-Ref

A stream reader class

createByString($content, $maxMemory = 2097152)   X-Ref
Creates a stream reader instance by a string value.

param: string $content
param: int $maxMemory
return: StreamReader

createByFile($filename)   X-Ref
Creates a stream reader instance by a filename.

param: string $filename
return: StreamReader

__construct($stream, $closeStream = false)   X-Ref
StreamReader constructor.

param: resource $stream
param: bool $closeStream Defines whether to close the stream resource if the instance is destructed or not.

__destruct()   X-Ref
The destructor.


cleanUp()   X-Ref
Closes the file handle.


getBufferLength($atOffset = false)   X-Ref
Returns the byte length of the buffer.

param: bool $atOffset
return: int

getPosition()   X-Ref
Get the current position in the stream.

return: int

getBuffer($atOffset = true)   X-Ref
Returns the current buffer.

param: bool $atOffset
return: string

getByte($position = null)   X-Ref
Gets a byte at a specific position in the buffer.

If the position is invalid the method will return false.

If the $position parameter is set to null the value of $this->offset will be used.

param: int|null $position
return: string|bool

readByte($position = null)   X-Ref
Returns a byte at a specific position, and set the offset to the next byte position.

If the position is invalid the method will return false.

If the $position parameter is set to null the value of $this->offset will be used.

param: int|null $position
return: string|bool

readBytes($length, $position = null)   X-Ref
Read bytes from the current or a specific offset position and set the internal pointer to the next byte.

If the position is invalid the method will return false.

If the $position parameter is set to null the value of $this->offset will be used.

param: int $length
param: int|null $position
return: string|false

readLine($length = 1024)   X-Ref
Read a line from the current position.

param: int $length
return: string|bool

setOffset($offset)   X-Ref
Set the offset position in the current buffer.

param: int $offset

getOffset()   X-Ref
Returns the current offset in the current buffer.

return: int

addOffset($offset)   X-Ref
Add an offset to the current offset.

param: int $offset

ensureContent()   X-Ref
Make sure that there is at least one character beyond the current offset in the buffer.

return: bool

getStream()   X-Ref
Returns the stream.

return: resource

getTotalLength()   X-Ref
Gets the total available length.

return: int

reset($pos = 0, $length = 200)   X-Ref
Resets the buffer to a position and re-read the buffer with the given length.

If the $pos parameter is negative the start buffer position will be the $pos'th position from
the end of the file.

If the $pos parameter is negative and the absolute value is bigger then the totalLength of
the file $pos will set to zero.

param: int|null $pos Start position of the new buffer
param: int $length Length of the new buffer. Mustn't be negative

ensure($pos, $length)   X-Ref
Ensures bytes in the buffer with a specific length and location in the file.

param: int $pos
param: int $length

increaseLength($minLength = 100)   X-Ref
Forcefully read more data into the buffer.

param: int $minLength
return: bool Returns false if the stream reaches the end