setasign\Fpdi\PdfParser

StreamReader A stream reader class

File: /FPDI v2/PdfParser/StreamReader.php

Class hierarchy

Summary

Properties

$buffer

protected string StreamReader::$buffer

The buffer.

$bufferLength

protected int StreamReader::$bufferLength

The buffer length.

$closeStream

protected bool StreamReader::$closeStream

Defines whether the stream should be closed when the stream reader instance is deconstructed or not.

$offset

protected int StreamReader::$offset

The byte-offset position in the buffer.

$position

protected int StreamReader::$position

The byte-offset position in the stream.

$stream

protected resource StreamReader::$stream

The stream resource.

$totalLength

protected int StreamReader::$totalLength

The total length of the stream.


Static Methods

createByFile()

public static StreamReader::createByFile (
string $filename
): StreamReader

Creates a stream reader instance by a filename.

Parameters
$filename : string
 

createByString()

public static StreamReader::createByString (
string $content [, int $maxMemory = 2097152 ]
): StreamReader

Creates a stream reader instance by a string value.

Parameters
$content : string
 
$maxMemory : int
 

Methods

__construct()

public StreamReader::__construct (
resource $stream [, bool $closeStream = false ]
)

StreamReader constructor.

Parameters
$stream : resource
 
$closeStream : bool

Defines whether to close the stream resource if the instance is destructed or not.

__destruct()

public StreamReader::__destruct (
void
): void

The destructor.

addOffset()

public StreamReader::addOffset (
int $offset
): void

Add an offset to the current offset.

Parameters
$offset : int
 

ensure()

public StreamReader::ensure (
int $pos, int $length
): void

Ensures bytes in the buffer with a specific length and location in the file.

Parameters
$pos : int
 
$length : int
 
See

ensureContent()

public StreamReader::ensureContent (
void
): bool

Make sure that there is at least one character beyond the current offset in the buffer.

getBuffer()

public StreamReader::getBuffer (
[ bool $atOffset = true ]
): string

Returns the current buffer.

Parameters
$atOffset : bool
 

getBufferLength()

public StreamReader::getBufferLength (
[ bool $atOffset = false ]
): int

Returns the byte length of the buffer.

Parameters
$atOffset : bool
 

getByte()

public StreamReader::getByte (
[ int|null $position = null ]
): string|bool

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.

Parameters
$position : int|null
 

getOffset()

public StreamReader::getOffset (
void
): int

Returns the current offset in the current buffer.

getPosition()

public StreamReader::getPosition (
void
): int

Get the current position in the stream.

getStream()

public StreamReader::getStream (
void
): resource

Returns the stream.

getTotalLength()

public StreamReader::getTotalLength (
void
): int

Gets the total available length.

increaseLength()

public StreamReader::increaseLength (
[ int $minLength = 100 ]
): bool

Forcefully read more data into the buffer.

Parameters
$minLength : int
 
Return Values

Returns false if the stream reaches the end

readByte()

public StreamReader::readByte (
[ int|null $position = null ]
): string|bool

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.

Parameters
$position : int|null
 

readBytes()

public StreamReader::readBytes (
int $length [, int|null $position = null ]
): string

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.

Parameters
$length : int
 
$position : int|null
 

readLine()

public StreamReader::readLine (
[ int $length = 1024 ]
): string|bool

Read a line from the current position.

Parameters
$length : int
 

reset()

public StreamReader::reset (
[ int|null $pos = 0 [, int $length = 200 ]]
): void

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.

Parameters
$pos : int|null

Start position of the new buffer

$length : int

Length of the new buffer. Mustn't be negative

setOffset()

public StreamReader::setOffset (
int $offset
): void

Set the offset position in the current buffer.

Parameters
$offset : int