class FileStream

extends Stream

This class provides a means for accessing a file for reading or writing

Description

Do not create instances of this class directly. The way to read / write a file is to use the Sys.openfile or Sys.createfile functions which will create an instance and return it for you. For methods that are availible for use please see below and Sys.Stream

class attributes [NB. Highlighted attributes are static members]
function truncate() - Truncate the file to the length specified
function seek() - Seek to a certain offset in the file from the place specified
function pos() - Get the current position in the file
function stat() - Stat the FileStream
function length() - Get the length of the file stream
function flock() - Attempt to gain an advisory lock on the file
function unlock() - Removes a lock that was placed with lock()
function toString() - Read the entire file into a string

Functions

function truncate Click to go up to the list
Truncate the file to the length specified
Declaration:
    native function truncate( number length )
Parameters:
    Parameter #1: number length - The length to use
Returns:
    'true' on sucess, 'false' otherwise with err.str being set

function seek Click to go up to the list
Seek to a certain offset in the file from the place specified
Declaration:
    native function seek( number offset, number whence )
Description:
The whence parameter can be one of Sys.SEEK_SET (offset relative to start of file), Sys.SEEK_CUR (offset relative to current position), or Sys.SEEK_END (offset relative to the end of the file).
Parameters:
    Parameter #1: number offset - The offset to seek to
    Parameter #2: number whence - How the offset should be interpreted
Returns:
    The new offset on success, -1 on error

function pos Click to go up to the list
Get the current position in the file
Declaration:
    native function pos( )
Returns:
    The offset on success, or -1 on fail

function stat Click to go up to the list
Stat the FileStream
Declaration:
    native function stat( )
Returns:
    A Sys.Stat object on success, null otherwise

function length Click to go up to the list
Get the length of the file stream
Declaration:
    native function length( )
Returns:
    The length on success or -1 on fail

function flock Click to go up to the list
Attempt to gain an advisory lock on the file
Declaration:
    native function flock(number shared, number wait)
Description:
This function attempts to obtain an advisory lock on the associated file using the flock() mechanism. Note that it is only useful if all mechanisms accessing the file also use the same locking mechanism as the OS itself will not enforce the lock. If shared is true, a shared lock will be attempted instead of the default exclusive type. A shared lock is one that multiple processes can share at the same time, but will still cause an attempted exclusive lock to fail. An exclusive lock is one that only one process can posess at a time. If wait is true and the lock is held by another process, the function will wait for the lock to become free and then take it straight away, rather than returning immediately. If an error occurs, it will return -1 and err.str will be set. If the lock attempt is successful, it will return 0. If wait is false and the lock is held by another process, it will return 1. To remove a lock, either call unlock() or close the file. Locks are automatically destroyed if the program exits. Note: this function is not available on all operating systems.
Parameters:
    Parameter #1: number shared - If true, get a shared lock instead of exclusive
    Parameter #2: number wait - If true, wait for the lock instead of failing
Returns:
    -1 on error, 0 on success, 1 if already locked

function unlock Click to go up to the list
Removes a lock that was placed with lock()
Declaration:
    native function unlock()
Description:
This function removes an advisory lock on the associated file which was created by the lock() function. If an error occurs, false is returned and err.str is set.
Returns:
    true on success or false on error

function toString Click to go up to the list
Read the entire file into a string
Returns:
    The string to read

Automatically generated at 8:45pm, Wednesday 08 January 2003 by feritedoc.