ReadWrite
extends Temporary
in package
implements
In, Out
Class \Hoa\File\Temporary\ReadWrite.
Read/write a temporary file.
Tags
Table of Contents
Interfaces
Properties
- $_i : int
- Temporary file index.
Methods
- __construct() : mixed
- Open a file.
- create() : string
- Create a unique temporary file, i.e. a file with a unique filename. It is different of calling $this->__construct() that will create a temporary file that will be destroy when calling the $this->close() method.
- eof() : bool
- Test for end-of-file.
- getTemporaryDirectory() : string
- Get the directory path used for temporary files.
- 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().
- scanf() : array<string|int, mixed>
- Parse input from a stream according to a format.
- truncate() : bool
- Truncate a file to a given length.
- 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.
- _open() : resource
- Open the stream and return the associated resource.
Properties
$_i
Temporary file index.
private
static int
$_i
= 0
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 parent::MODE_* constants.
- $context : string = null
-
Context ID (please, see the \Hoa\Stream\Context class).
- $wait : bool = false
-
Differ opening or not.
create()
Create a unique temporary file, i.e. a file with a unique filename. It is different of calling $this->__construct() that will create a temporary file that will be destroy when calling the $this->close() method.
public
static create([string $directory = null ][, string $prefix = '__hoa_' ]) : string
Parameters
- $directory : string = null
-
Directory where the temporary filename will be created. If the directory does not exist, it may generate a file in the system's temporary directory.
- $prefix : string = '__hoa_'
-
Prefix of the generated temporary filename.
Return values
stringeof()
Test for end-of-file.
public
eof() : bool
Return values
boolgetTemporaryDirectory()
Get the directory path used for temporary files.
public
static getTemporaryDirectory() : string
Return values
stringread()
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
stringscanf()
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>truncate()
Truncate a file to a given length.
public
truncate(int $size) : bool
Parameters
- $size : int
-
Size.
Return values
boolwrite()
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.
_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.