Class SafeStream (namespace Nette\IO)


Thread safe / atomic file manipulation. Stream safe://

  1. 1:  file_put_contents('safe://myfile.txt'$content);
  2. 2:  
  3. 3:  $content file_get_contents('safe://myfile.txt');
  4. 4:  
  5. 5:  unlink('safe://myfile.txt');


Author: David Grudl
Copyright: Copyright (c) 2004, 2009 David Grudl
Located: in /IO/SafeStream.php (line 39)
Public Method Summary
static bool
Registers protocol 'safe://'.
void
Closes file.
bool
Returns TRUE if the file pointer is at end-of-file.
bool
stream_open (string $path, string $mode, int $options, string &$opened_path)
Opens file.
string
stream_read (int $length)
Reads up to length bytes from the file.
int
stream_seek (int $offset, int $whence)
Sets the file position indicator for the file.
array
Gets information about a file referenced by $this->handle.
int
Returns the position of the file.
int
stream_write (string $data)
Writes the string to the file.
bool
unlink (string $path)
Deletes a file.
array
url_stat (string $path, int $flags)
Gets information about a file referenced by filename.
Constant Summary
string PROTOCOL 'safe'

line 44

Name of stream protocol - safe://

Method Details

line 74

register

public static bool register ()

Registers protocol 'safe://'.

Output
bool  

line 174

stream_close

public void stream_close ()

Closes file.

Output
void  

line 243

stream_eof

public bool stream_eof ()

Returns TRUE if the file pointer is at end-of-file.

Output
bool  

line 90

stream_open

public bool stream_open (string $path, string $mode, int $options, string &$opened_path)

Opens file.

Input
string $path file name with stream protocol
string $mode mode - see fopen()
int $options STREAM_USE_PATH, STREAM_REPORT_ERRORS
string &$opened_path full path
Output
bool TRUE on success or FALSE on failure

line 199

stream_read

public string stream_read (int $length)

Reads up to length bytes from the file.

Input
int $length length
Output
string  

line 257

stream_seek

public int stream_seek (int $offset, int $whence)

Sets the file position indicator for the file.

Input
int $offset position
int $whence see fseek()
Output
int Return TRUE on success

line 269

stream_stat

public array stream_stat ()

Gets information about a file referenced by $this->handle.

Output
array  

line 231

stream_tell

public int stream_tell ()

Returns the position of the file.

Output
int  

line 212

stream_write

public int stream_write (string $data)

Writes the string to the file.

Input
string $data data to write
Output
int number of bytes that were successfully stored

line 283

url_stat

public array url_stat (string $path, int $flags)

Gets information about a file referenced by filename.

Input
string $path file name
int $flags STREAM_URL_STAT_LINK, STREAM_URL_STAT_QUIET
Output
array