Index Documentation

FileStream extends GenericStream
in package

Represents a Stream representing a file.

Table of Contents

Constants

APPEND_READ_WRITE  = 'a+b'
Open file for reading and appending, create if not exist.
APPEND_WRITE  = 'ab'
Open file for appending, create if not exist.
CREATE_READ_WRITE  = 'x+b'
Create file for reading and writing, throw if exist.
CREATE_WRITE  = 'xb'
Create file for writing, throw if exist.
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.
LOCK_NON_BLOCKING  = LOCK_NB
Don't block during lock attempt.
LOCK_NONE  = 0
Don't lock file.
LOCK_READ  = LOCK_SH
Lock for reading.
LOCK_WRITE  = LOCK_EX
Lock for writing.
NEW_READ_WRITE  = 'w+b'
Create file for reading and writing, truncate if exist.
NEW_WRITE  = 'wb'
Create file for writing, truncate if exist.
OPEN_OR_CREATE_READ_WRITE  = 'c+b'
Opens or creates a file for reading and writing.
OPEN_OR_CREATE_WRITE  = 'cb'
Opens or creates a file for writing.
OPEN_READ  = 'rb'
Open file for reading, throw if not exists.
OPEN_READ_WRITE  = 'r+b'
Open file for reading and writing, throw if not exist.
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
appendReadWrite()  : FileStream
Open file for reading and appending, create if not exist.
appendWrite()  : FileStream
Open file for appending, create if not exist.
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.
createReadWrite()  : FileStream
Create file for reading and writing, throw if exist.
createWrite()  : FileStream
Create file for writing, throw if exist.
flush()  : void
Force write of all buffered output to the stream.
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.
newReadWrite()  : FileStream
Create file for reading and writing, truncate if exist.
newWrite()  : FileStream
Create file for writing, truncate if exist.
openOrCreateReadWrite()  : FileStream
Opens or creates a file for reading and writing.
openOrCreateWrite()  : FileStream
Opens or creates a file for writing.
openRead()  : FileStream
Open file for reading, throw if not exists.
openReadWrite()  : FileStream
Open file for reading and writing, throw if not exist.
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

APPEND_READ_WRITE

Open file for reading and appending, create if not exist.

public string APPEND_READ_WRITE = 'a+b'

APPEND_WRITE

Open file for appending, create if not exist.

public string APPEND_WRITE = 'ab'

CREATE_READ_WRITE

Create file for reading and writing, throw if exist.

public string CREATE_READ_WRITE = 'x+b'

CREATE_WRITE

Create file for writing, throw if exist.

public string CREATE_WRITE = 'xb'

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

LOCK_NON_BLOCKING

Don't block during lock attempt.

public int LOCK_NON_BLOCKING = LOCK_NB

LOCK_NONE

Don't lock file.

public int LOCK_NONE = 0

LOCK_READ

Lock for reading.

public int LOCK_READ = LOCK_SH

LOCK_WRITE

Lock for writing.

public int LOCK_WRITE = LOCK_EX

NEW_READ_WRITE

Create file for reading and writing, truncate if exist.

public string NEW_READ_WRITE = 'w+b'

NEW_WRITE

Create file for writing, truncate if exist.

public string NEW_WRITE = 'wb'

OPEN_OR_CREATE_READ_WRITE

Opens or creates a file for reading and writing.

public string OPEN_OR_CREATE_READ_WRITE = 'c+b'

OPEN_OR_CREATE_WRITE

Opens or creates a file for writing.

public string OPEN_OR_CREATE_WRITE = 'cb'

OPEN_READ

Open file for reading, throw if not exists.

public string OPEN_READ = 'rb'

OPEN_READ_WRITE

Open file for reading and writing, throw if not exist.

public string OPEN_READ_WRITE = 'r+b'

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 $path, string $mode, int $lock) : mixed
Parameters
$path : string

Path to the file.

$mode : string

Stream mode to use to open the file.

$lock : int

Locking method to use.

Tags
throws
RuntimeException

If the file could not be opened.

__destruct()

public __destruct() : mixed

__toString()

public __toString() : string
Return values
string

appendReadWrite()

Open file for reading and appending, create if not exist.

public static appendReadWrite(string $path[, int $lock = self::LOCK_NONE ]) : FileStream
Parameters
$path : string

Path to the file.

$lock : int = self::LOCK_NONE

Locking method to use.

Return values
FileStream

Stream to file.

appendWrite()

Open file for appending, create if not exist.

public static appendWrite(string $path[, int $lock = self::LOCK_NONE ]) : FileStream
Parameters
$path : string

Path to the file.

$lock : int = self::LOCK_NONE

Locking method to use.

Return values
FileStream

Stream to file.

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]

createReadWrite()

Create file for reading and writing, throw if exist.

public static createReadWrite(string $path[, int $lock = self::LOCK_NONE ]) : FileStream
Parameters
$path : string

Path to the file.

$lock : int = self::LOCK_NONE

Locking method to use.

Return values
FileStream

Stream to file.

createWrite()

Create file for writing, throw if exist.

public static createWrite(string $path[, int $lock = self::LOCK_NONE ]) : FileStream
Parameters
$path : string

Path to the file.

$lock : int = self::LOCK_NONE

Locking method to use.

Return values
FileStream

Stream to file.

flush()

Force write of all buffered output to the stream.

public flush() : void

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.

newReadWrite()

Create file for reading and writing, truncate if exist.

public static newReadWrite(string $path[, int $lock = self::LOCK_NONE ]) : FileStream
Parameters
$path : string

Path to the file.

$lock : int = self::LOCK_NONE

Locking method to use.

Return values
FileStream

Stream to file.

newWrite()

Create file for writing, truncate if exist.

public static newWrite(string $path[, int $lock = self::LOCK_NONE ]) : FileStream
Parameters
$path : string

Path to the file.

$lock : int = self::LOCK_NONE

Locking method to use.

Return values
FileStream

Stream to file.

openOrCreateReadWrite()

Opens or creates a file for reading and writing.

public static openOrCreateReadWrite(string $path[, int $lock = self::LOCK_NONE ]) : FileStream
Parameters
$path : string

Path to the file.

$lock : int = self::LOCK_NONE

Locking method to use.

Return values
FileStream

Stream to file.

openOrCreateWrite()

Opens or creates a file for writing.

public static openOrCreateWrite(string $path[, int $lock = self::LOCK_NONE ]) : FileStream
Parameters
$path : string

Path to the file.

$lock : int = self::LOCK_NONE

Locking method to use.

Return values
FileStream

Stream to file.

openRead()

Open file for reading, throw if not exists.

public static openRead(string $path[, int $lock = self::LOCK_NONE ]) : FileStream
Parameters
$path : string

Path to the file.

$lock : int = self::LOCK_NONE

Locking method to use.

Return values
FileStream

Stream to file.

openReadWrite()

Open file for reading and writing, throw if not exist.

public static openReadWrite(string $path[, int $lock = self::LOCK_NONE ]) : FileStream
Parameters
$path : string

Path to the file.

$lock : int = self::LOCK_NONE

Locking method to use.

Return values
FileStream

Stream to 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