Index Documentation

TempFileStream extends GenericStream
in package

Represents a temporary file stream. Will remain in memory if the size is below a given threshold.

Table of Contents

Constants

CURRENT  = SEEK_CUR
Place the cursor relative to the current position of the cursor.
END  = SEEK_END
Place the cursor relative to the end of the file.
MAX_MEMORY  = 2 * 1024 * 1024
Default maximum size the stream can be to remain in memory and not be written to disk.
READABLE  = ['r', 'rb', 'r+', 'r+b', 'w+', 'w+b', 'a+', 'a+b', 'x+', 'x+b', 'c+', 'c+b']
Readable file modes.
START  = SEEK_SET
Place the cursor relative to the start of the file.
WRITEABLE  = ['r+', 'r+b', 'w', 'wb', 'w+', 'w+b', 'a', 'ab', 'a+', 'a+b', 'x', 'xb', 'x+', 'x+b', 'c', 'cb', 'c+', 'c+b']
Writeable file modes.

Methods

__construct()  : mixed
__destruct()  : mixed
__toString()  : string
canRead()  : bool
Whether this stream is readable.
canSeek()  : bool
Whether this stream is seekable.
canWrite()  : bool
Whether this stream is writeable.
close()  : void
Free, release or reset unmanaged resources.
copyTo()  : void
Copy the entire contents of this stream to another.
flush()  : void
Force write of all buffered output to the stream.
fromString()  : TempFileStream
Creates a TempFileStream from a string.
getLength()  : int
Retrieves the current length of the stream.
getPosition()  : int
Retrieves the current cursor position.
getResource()  : resource
Returns the underlying resource handle.
hasTimedOut()  : bool
Whether this stream has timed out.
isBlocking()  : bool
Whether this stream has blocking operations.
isEnded()  : bool
Whether the cursor is at the end of the file.
read()  : string|null
Read an amount of data from the stream.
readByte()  : int
Read a single byte from the stream.
readChar()  : string|null
Read a single character from the stream.
readLine()  : string|null
Read a line of text from the stream.
seek()  : bool
Move the cursor to a different place in the stream.
setLength()  : void
Sets the length of the stream.
write()  : void
Write an amount of data to the stream.
writeByte()  : void
Writes a single byte to the stream.
writeChar()  : void
Writes a single character to the stream.
writeLine()  : void
Writes a line of text to the stream.

Constants

CURRENT

Place the cursor relative to the current position of the cursor.

public int CURRENT = SEEK_CUR

END

Place the cursor relative to the end of the file.

public int END = SEEK_END

MAX_MEMORY

Default maximum size the stream can be to remain in memory and not be written to disk.

public int MAX_MEMORY = 2 * 1024 * 1024

READABLE

Readable file modes.

public array<string|int, string> READABLE = ['r', 'rb', 'r+', 'r+b', 'w+', 'w+b', 'a+', 'a+b', 'x+', 'x+b', 'c+', 'c+b']

START

Place the cursor relative to the start of the file.

public int START = SEEK_SET

WRITEABLE

Writeable file modes.

public array<string|int, string> WRITEABLE = ['r+', 'r+b', 'w', 'wb', 'w+', 'w+b', 'a', 'ab', 'a+', 'a+b', 'x', 'xb', 'x+', 'x+b', 'c', 'cb', 'c+', 'c+b']

Methods

__construct()

public __construct([string|null $body = null ][, int $maxMemory = self::MAX_MEMORY ]) : mixed
Parameters
$body : string|null = null

Contents of the stream.

$maxMemory : int = self::MAX_MEMORY

Maximum filesize until the file is moved out of memory and to disk.

__destruct()

public __destruct() : mixed

__toString()

public __toString() : string
Return values
string

canRead()

Whether this stream is readable.

public canRead() : bool
Return values
bool

true if the stream is readable.

canSeek()

Whether this stream is seekable.

public canSeek() : bool
Return values
bool

true if the stream is seekable.

canWrite()

Whether this stream is writeable.

public canWrite() : bool
Return values
bool

true if the stream is writeable.

close()

Free, release or reset unmanaged resources.

public close() : void

copyTo()

Copy the entire contents of this stream to another.

public copyTo(Stream $other) : void

Will seek to the beginning of the stream if the stream is seekable.

Parameters
$other : Stream

Target stream.

Attributes
#[Override]

flush()

Force write of all buffered output to the stream.

public flush() : void

fromString()

Creates a TempFileStream from a string.

public static fromString(string $string) : TempFileStream
Parameters
$string : string

Data to write to the temporary file.

Return values
TempFileStream

Stream representing the given text.

getLength()

Retrieves the current length of the stream.

public getLength() : int
Return values
int

Stream length.

getPosition()

Retrieves the current cursor position.

public getPosition() : int
Return values
int

Cursor position.

getResource()

Returns the underlying resource handle.

public getResource() : resource
Return values
resource

Underlying resource handle.

hasTimedOut()

Whether this stream has timed out.

public hasTimedOut() : bool
Return values
bool

true if the stream has timed out.

isBlocking()

Whether this stream has blocking operations.

public isBlocking() : bool
Return values
bool

true if the stream has blocking operations.

isEnded()

Whether the cursor is at the end of the file.

public isEnded() : bool
Return values
bool

true if the cursor is at the end of the file.

read()

Read an amount of data from the stream.

public read(int $length) : string|null
Parameters
$length : int

Maximum amount of data to read.

Return values
string|null

At most a $length sized string or null if we're at the end of the stream.

readByte()

Read a single byte from the stream.

public readByte() : int
Return values
int

One byte or -1 if we're at the end of the stream.

readChar()

Read a single character from the stream.

public readChar() : string|null
Return values
string|null

One character or null if we're at the end of the stream.

readLine()

Read a line of text from the stream.

public readLine() : string|null
Return values
string|null

One line of text or null if we're at the end of the stream.

seek()

Move the cursor to a different place in the stream.

public seek(int $offset[, int $origin = Stream::START ]) : bool
Parameters
$offset : int

Offset to apply to the cursor position.

$origin : int = Stream::START

Point from which to apply the offset.

Return values
bool

true if the cursor offset was applied successfully.

setLength()

Sets the length of the stream.

public setLength(int $length) : void
Parameters
$length : int

Desired stream length.

write()

Write an amount of data to the stream.

public write(string $buffer[, int $length = -1 ]) : void
Parameters
$buffer : string

Buffer to write from.

$length : int = -1

Amount of data to write from the buffer, or -1 to write the entire buffer.

writeByte()

Writes a single byte to the stream.

public writeByte(int $byte) : void
Parameters
$byte : int

Byte to write to the stream.

writeChar()

Writes a single character to the stream.

public writeChar(string $char) : void
Parameters
$char : string

Character to write to the stream.

writeLine()

Writes a line of text to the stream.

public writeLine(string $line) : void
Parameters
$line : string

Line of text to write.


        
On this page

Search results