ReadWrite
extends File
in package
implements
In, Out
Class \Hoa\File\ReadWrite.
File handler.
Tags
Table of Contents
Interfaces
Constants
- MODE_APPEND_READ_WRITE = 'a+b'
- Open for reading and writing; place the file pointer at the end of the file. If the file does not exist, attempt to create it.
- MODE_APPEND_WRITE = 'ab'
- Open for writing only; place the file pointer at the end of the file. If the file does not exist, attempt to create it.
- MODE_CREATE_READ_WRITE = 'x+b'
- Create and open for reading and writing; place the file pointer at the beginning of the file. If the file already exists, the fopen() call with fail by returning false and generating an error of level E_WARNING. If the file does not exist, attempt to create it. This is equivalent to specifying O_EXCL | O_CREAT flags for the underlying open(2) system call.
- MODE_CREATE_WRITE = 'xb'
- Create and open for writing only; place the file pointer at the beginning of the file. If the file already exits, the fopen() call with fail by returning false and generating an error of level E_WARNING. If the file does not exist, attempt to create it. This is equivalent to specifying O_EXCL | O_CREAT flags for the underlying open(2) system call.
- MODE_READ = 'rb'
- Open for reading only; place the file pointer at the beginning of the file.
- MODE_READ_WRITE = 'r+b'
- Open for reading and writing; place the file pointer at the beginning of the file.
- MODE_TRUNCATE_READ_WRITE = 'w+b'
- Open for reading and writing; place the file pointer at the beginning of the file and truncate the file to zero length. If the file does not exist, attempt to create it.
- MODE_TRUNCATE_WRITE = 'wb'
- Open for writing only; place the file pointer at the beginning of the file and truncate the file to zero length. If the file does not exist, attempt to create it.
Properties
- $_mode : string
- Mode.
Methods
- __construct() : mixed
- Open a file.
- changeGroup() : bool
- Change file group.
- changeMode() : bool
- Change file mode.
- changeOwner() : bool
- Change file owner.
- clearAllStatisticCaches() : void
- Clear all files status cache.
- clearStatisticCache() : void
- Clear file status cache.
- copy() : bool
- Copy file.
- create() : bool
- Create a file.
- delete() : bool
- Delete a file.
- deleteBuffer() : bool
- Delete buffer.
- eof() : bool
- Test for end-of-file.
- flush() : bool
- Flush the output to a stream.
- getATime() : int
- Get last access time of file.
- getBasename() : string
- Get filename component of path.
- getBufferLevel() : int
- Get bufffer level.
- getBufferSize() : int
- Get buffer size.
- getCTime() : int
- Get inode change time of file.
- getDirname() : string
- Get directory name component of path.
- getExtension() : string
- Get file extension (if exists).
- getFilename() : string
- Get filename without extension.
- getGroup() : int
- Get file group.
- getINode() : int
- Get inode.
- getMode() : string
- Get the open mode.
- getMTime() : int
- Get file modification time.
- getOwner() : int
- Get file owner.
- getPermissions() : int
- Get file permissions.
- getReadablePermissions() : string
- Get file permissions as a string.
- getRealPath() : string
- Get a canonicalized absolute pathname.
- getSize() : int
- Get size.
- getStatistic() : array<string|int, mixed>
- Get informations about a file.
- isBlockSpecial() : bool
- Check if it is block special.
- isCaseSensitive() : bool
- Check if the system is case sensitive or not.
- isCharacterSpecial() : bool
- Check if it is character special file.
- isDirectory() : bool
- Check if it is a directory.
- isExecutable() : bool
- Check if the file is executable.
- isFIFOPipe() : bool
- Check if it is a FIFO pipe.
- isFile() : bool
- Check if it is a file.
- isLink() : bool
- Check if it is a link.
- isReadable() : bool
- Check if the file is readable.
- isSocket() : bool
- Check if it is a socket.
- isUnknown() : bool
- Check if it is an unknown type.
- isWritable() : bool
- Check if the file is writable.
- lock() : bool
- Portable advisory locking.
- move() : bool
- Move a file.
- newBuffer() : int
- Start a new buffer.
- read() : string
- Read n characters.
- readAll() : string
- Read all, i.e. read as much as possible.
- readArray() : array<string|int, mixed>
- Read an array.
- readBoolean() : bool
- Read a boolean.
- readCharacter() : string
- Read a character.
- readFloat() : float
- Read a float.
- readInteger() : int
- Read an integer.
- readLine() : string
- Read a line.
- readString() : string
- Alias of $this->read().
- rewind() : bool
- Rewind the position of a stream pointer.
- scanf() : array<string|int, mixed>
- Parse input from a stream according to a format.
- seek() : int
- Seek on a stream pointer.
- tell() : int
- Get the current position of the stream pointer.
- touch() : bool
- Set access and modification time of file.
- truncate() : bool
- Truncate a file to a given length.
- umask() : int
- Change the current umask.
- write() : mixed
- Write n characters.
- writeAll() : mixed
- Write all, i.e. as much as possible.
- writeArray() : mixed
- Write an array.
- writeBoolean() : mixed
- Write a boolean.
- writeCharacter() : mixed
- Write a character.
- writeFloat() : mixed
- Write a float.
- writeInteger() : mixed
- Write an integer.
- writeLine() : mixed
- Write a line.
- writeString() : mixed
- Write a string.
- _close() : bool
- Close the current stream.
- _open() : resource
- Open the stream and return the associated resource.
- setMode() : string
- Set the open mode.
Constants
MODE_APPEND_READ_WRITE
Open for reading and writing; place the file pointer at the end of the file. If the file does not exist, attempt to create it.
public
mixed
MODE_APPEND_READ_WRITE
= 'a+b'
Tags
MODE_APPEND_WRITE
Open for writing only; place the file pointer at the end of the file. If the file does not exist, attempt to create it.
public
mixed
MODE_APPEND_WRITE
= 'ab'
Tags
MODE_CREATE_READ_WRITE
Create and open for reading and writing; place the file pointer at the beginning of the file. If the file already exists, the fopen() call with fail by returning false and generating an error of level E_WARNING. If the file does not exist, attempt to create it. This is equivalent to specifying O_EXCL | O_CREAT flags for the underlying open(2) system call.
public
mixed
MODE_CREATE_READ_WRITE
= 'x+b'
Tags
MODE_CREATE_WRITE
Create and open for writing only; place the file pointer at the beginning of the file. If the file already exits, the fopen() call with fail by returning false and generating an error of level E_WARNING. If the file does not exist, attempt to create it. This is equivalent to specifying O_EXCL | O_CREAT flags for the underlying open(2) system call.
public
mixed
MODE_CREATE_WRITE
= 'xb'
Tags
MODE_READ
Open for reading only; place the file pointer at the beginning of the file.
public
mixed
MODE_READ
= 'rb'
Tags
MODE_READ_WRITE
Open for reading and writing; place the file pointer at the beginning of the file.
public
mixed
MODE_READ_WRITE
= 'r+b'
Tags
MODE_TRUNCATE_READ_WRITE
Open for reading and writing; place the file pointer at the beginning of the file and truncate the file to zero length. If the file does not exist, attempt to create it.
public
mixed
MODE_TRUNCATE_READ_WRITE
= 'w+b'
Tags
MODE_TRUNCATE_WRITE
Open for writing only; place the file pointer at the beginning of the file and truncate the file to zero length. If the file does not exist, attempt to create it.
public
mixed
MODE_TRUNCATE_WRITE
= 'wb'
Tags
Properties
$_mode
Mode.
protected
string
$_mode
= null
Methods
__construct()
Open a file.
public
__construct(string $streamName[, string $mode = parent::MODE_APPEND_READ_WRITE ][, string $context = null ][, bool $wait = false ]) : mixed
Parameters
- $streamName : string
-
Stream name.
- $mode : string = parent::MODE_APPEND_READ_WRITE
-
Open mode, see the self::MODE_* constants.
- $context : string = null
-
Context ID (please, see the \Hoa\Stream\Context class).
- $wait : bool = false
-
Differ opening or not.
changeGroup()
Change file group.
public
changeGroup(mixed $group) : bool
Parameters
- $group : mixed
-
Group name or number.
Return values
boolchangeMode()
Change file mode.
public
changeMode(int $mode) : bool
Parameters
- $mode : int
-
Mode (in octal!).
Return values
boolchangeOwner()
Change file owner.
public
changeOwner(mixed $user) : bool
Parameters
- $user : mixed
-
User.
Return values
boolclearAllStatisticCaches()
Clear all files status cache.
public
static clearAllStatisticCaches() : void
clearStatisticCache()
Clear file status cache.
public
clearStatisticCache() : void
copy()
Copy file.
public
copy(string $to[, bool $force = StreamIStreamTouchable::DO_NOT_OVERWRITE ]) : bool
Return the destination file path if succeed, false otherwise.
Parameters
- $to : string
-
Destination path.
- $force : bool = StreamIStreamTouchable::DO_NOT_OVERWRITE
-
Force to copy if the file $to already exists. Use the \Hoa\Stream\IStream\Touchable::*OVERWRITE constants.
Return values
boolcreate()
Create a file.
public
static create(string $name, mixed $dummy) : bool
Parameters
- $name : string
-
File name.
- $dummy : mixed
-
To be compatible with childs.
Return values
booldelete()
Delete a file.
public
delete() : bool
Return values
booldeleteBuffer()
Delete buffer.
public
deleteBuffer() : bool
Return values
booleof()
Test for end-of-file.
public
eof() : bool
Return values
boolflush()
Flush the output to a stream.
public
flush() : bool
Return values
boolgetATime()
Get last access time of file.
public
getATime() : int
Return values
intgetBasename()
Get filename component of path.
public
getBasename() : string
Return values
stringgetBufferLevel()
Get bufffer level.
public
getBufferLevel() : int
Return values
intgetBufferSize()
Get buffer size.
public
getBufferSize() : int
Return values
intgetCTime()
Get inode change time of file.
public
getCTime() : int
Return values
intgetDirname()
Get directory name component of path.
public
getDirname() : string
Return values
stringgetExtension()
Get file extension (if exists).
public
getExtension() : string
Return values
stringgetFilename()
Get filename without extension.
public
getFilename() : string
Return values
stringgetGroup()
Get file group.
public
getGroup() : int
Return values
intgetINode()
Get inode.
public
getINode() : int
Return values
intgetMode()
Get the open mode.
public
getMode() : string
Return values
stringgetMTime()
Get file modification time.
public
getMTime() : int
Return values
intgetOwner()
Get file owner.
public
getOwner() : int
Return values
intgetPermissions()
Get file permissions.
public
getPermissions() : int
Return values
intgetReadablePermissions()
Get file permissions as a string.
public
getReadablePermissions() : string
Result sould be interpreted like this:
- s: socket;
- l: symbolic link;
- -: regular;
- b: block special;
- d: directory;
- c: character special;
- p: FIFO pipe;
- u: unknown.
Return values
stringgetRealPath()
Get a canonicalized absolute pathname.
public
getRealPath() : string
Return values
stringgetSize()
Get size.
public
getSize() : int
Return values
intgetStatistic()
Get informations about a file.
public
getStatistic() : array<string|int, mixed>
Return values
array<string|int, mixed>isBlockSpecial()
Check if it is block special.
public
isBlockSpecial() : bool
Return values
boolisCaseSensitive()
Check if the system is case sensitive or not.
public
static isCaseSensitive() : bool
Return values
boolisCharacterSpecial()
Check if it is character special file.
public
isCharacterSpecial() : bool
Return values
boolisDirectory()
Check if it is a directory.
public
isDirectory() : bool
Return values
boolisExecutable()
Check if the file is executable.
public
isExecutable() : bool
Return values
boolisFIFOPipe()
Check if it is a FIFO pipe.
public
isFIFOPipe() : bool
Return values
boolisFile()
Check if it is a file.
public
isFile() : bool
Return values
boolisLink()
Check if it is a link.
public
isLink() : bool
Return values
boolisReadable()
Check if the file is readable.
public
isReadable() : bool
Return values
boolisSocket()
Check if it is a socket.
public
isSocket() : bool
Return values
boolisUnknown()
Check if it is an unknown type.
public
isUnknown() : bool
Return values
boolisWritable()
Check if the file is writable.
public
isWritable() : bool
Return values
boollock()
Portable advisory locking.
public
lock(int $operation) : bool
Parameters
- $operation : int
-
Operation, use the \Hoa\Stream\IStream\Lockable::LOCK_* constants.
Return values
boolmove()
Move a file.
public
move(string $name[, bool $force = StreamIStreamTouchable::DO_NOT_OVERWRITE ][, bool $mkdir = StreamIStreamTouchable::DO_NOT_MAKE_DIRECTORY ]) : bool
Parameters
- $name : string
-
New name.
- $force : bool = StreamIStreamTouchable::DO_NOT_OVERWRITE
-
Force to move if the file $name already exists. Use the \Hoa\Stream\IStream\Touchable::*OVERWRITE constants.
- $mkdir : bool = StreamIStreamTouchable::DO_NOT_MAKE_DIRECTORY
-
Force to make directory if does not exist. Use the \Hoa\Stream\IStream\Touchable::*DIRECTORY constants.
Return values
boolnewBuffer()
Start a new buffer.
public
newBuffer([mixed $callable = null ][, int $size = null ]) : int
The callable acts like a light filter.
Parameters
- $callable : mixed = null
-
Callable.
- $size : int = null
-
Size.
Return values
intread()
Read n characters.
public
read(int $length) : string
Parameters
- $length : int
-
Length.
Tags
Return values
stringreadAll()
Read all, i.e. read as much as possible.
public
readAll([int $offset = 0 ]) : string
Parameters
- $offset : int = 0
-
Offset.
Return values
stringreadArray()
Read an array.
public
readArray([string $format = null ]) : array<string|int, mixed>
Alias of the $this->scanf() method.
Parameters
- $format : string = null
-
Format (see printf's formats).
Return values
array<string|int, mixed>readBoolean()
Read a boolean.
public
readBoolean() : bool
Return values
boolreadCharacter()
Read a character.
public
readCharacter() : string
Return values
stringreadFloat()
Read a float.
public
readFloat([int $length = 1 ]) : float
Parameters
- $length : int = 1
-
Length.
Return values
floatreadInteger()
Read an integer.
public
readInteger([int $length = 1 ]) : int
Parameters
- $length : int = 1
-
Length.
Return values
intreadLine()
Read a line.
public
readLine() : string
Return values
stringreadString()
Alias of $this->read().
public
readString(int $length) : string
Parameters
- $length : int
-
Length.
Return values
stringrewind()
Rewind the position of a stream pointer.
public
rewind() : bool
Return values
boolscanf()
Parse input from a stream according to a format.
public
scanf(string $format) : array<string|int, mixed>
Parameters
- $format : string
-
Format (see printf's formats).
Return values
array<string|int, mixed>seek()
Seek on a stream pointer.
public
seek(int $offset[, int $whence = StreamIStreamPointable::SEEK_SET ]) : int
Parameters
- $offset : int
-
Offset (negative value should be supported).
- $whence : int = StreamIStreamPointable::SEEK_SET
-
Whence, use the \Hoa\Stream\IStream\Pointable::SEEK_* constants.
Return values
inttell()
Get the current position of the stream pointer.
public
tell() : int
Return values
inttouch()
Set access and modification time of file.
public
touch([int $time = -1 ][, int $atime = -1 ]) : bool
Parameters
- $time : int = -1
-
Time. If equals to -1, time() should be used.
- $atime : int = -1
-
Access time. If equals to -1, $time should be used.
Return values
booltruncate()
Truncate a file to a given length.
public
truncate(int $size) : bool
Parameters
- $size : int
-
Size.
Return values
boolumask()
Change the current umask.
public
static umask([int $umask = null ]) : int
Parameters
- $umask : int = null
-
Umask (in octal!). If null, given the current umask value.
Return values
intwrite()
Write n characters.
public
write(string $string, int $length) : mixed
Parameters
- $string : string
-
String.
- $length : int
-
Length.
Tags
writeAll()
Write all, i.e. as much as possible.
public
writeAll(string $string) : mixed
Parameters
- $string : string
-
String.
writeArray()
Write an array.
public
writeArray(array<string|int, mixed> $array) : mixed
Parameters
- $array : array<string|int, mixed>
-
Array.
writeBoolean()
Write a boolean.
public
writeBoolean(bool $boolean) : mixed
Parameters
- $boolean : bool
-
Boolean.
writeCharacter()
Write a character.
public
writeCharacter(string $char) : mixed
Parameters
- $char : string
-
Character.
writeFloat()
Write a float.
public
writeFloat(float $float) : mixed
Parameters
- $float : float
-
Float.
writeInteger()
Write an integer.
public
writeInteger(int $integer) : mixed
Parameters
- $integer : int
-
Integer.
writeLine()
Write a line.
public
writeLine(string $line) : mixed
Parameters
- $line : string
-
Line.
writeString()
Write a string.
public
writeString(string $string) : mixed
Parameters
- $string : string
-
String.
_close()
Close the current stream.
protected
_close() : bool
Return values
bool_open()
Open the stream and return the associated resource.
protected
& _open(string $streamName[, Context $context = null ]) : resource
Parameters
- $streamName : string
-
Stream name (e.g. path or URL).
- $context : Context = null
-
Context.
Tags
Return values
resourcesetMode()
Set the open mode.
protected
setMode(string $mode) : string
Parameters
- $mode : string
-
Open mode. Please, see the child::MODE_* constants.