class JStream extends JObject


Located at : UKNOWVA_ROOT/libraries/joomla/filesystem/stream.php

Joomla! Stream Interface

The Joomla! stream interface is designed to handle files as streams where as the legacy JFile static class treated files in a rather atomic manner.

This class adheres to the stream wrapper operations:

Methods

__construct(string $writeprefix = '', string $readprefix = '', string $context = array())

Constructor

string
__toString()

Magic method to convert the object to a string gracefully.

from JObject
mixed
def(string $property, mixed $default = null)

Sets a default value if not alreay assigned

from JObject
mixed
get(string $property, mixed $default = null)

Returns a property of the object or the default value if the property is not set.

from JObject
array
getProperties(boolean $public = true)

Returns an associative array of object properties.

from JObject
string
getError(integer $i = null, boolean $toString = true)

Get the most recent error message.

from JObject
array
getErrors()

Return all errors, if any.

from JObject
mixed
set(string $property, mixed $value = null)

Modifies a property of the object, creating it if it does not already exist.

from JObject
boolean
setProperties(mixed $properties)

Set the object properties based on a named array/hash.

from JObject
void
setError(string $error)

Add an error message.

from JObject
string
toString() deprecated

No description

from JObject
void
__destruct()

Destructor

boolean
open(string $filename, string $mode = 'r', bool $use_include_path = false, resource $context = null, bool $use_prefix = false, bool $relative = false, bool $detectprocessingmode = false)

Generic File Operations

boolean
close()

Attempt to close a file handle

boolean
eof()

Work out if we're at the end of the file for a stream

mixed
filesize()

Retrieve the file size of the path

mixed
gets(integer $length)

No description

mixed
read(integer $length)

Read a file

boolean
seek(integer $offset, integer $whence = SEEK_SET)

Seek the file

mixed
tell()

No description

boolean
write(string $string, integer $length, integer $chunk)

File write

boolean
chmod(string $filename = '', mixed $mode)

Chmod wrapper

array
get_meta_data()

Get the stream metadata

mixed
_buildContext()

Stream contexts Builds the context from the array

void
setContextOptions(array $context)

Updates the context to the array

void
addContextEntry(string $wrapper, string $name, string $value)

Adds a particular options to the context

void
deleteContextEntry(string $wrapper, string $name)

Deletes a particular setting from a context

mixed
applyContextToStream()

Applies the current context to the stream

mixed
appendFilter($filtername, $read_write = STREAM_FILTER_READ, $params = array())

Stream filters Append a filter to the chain

mixed
prependFilter($filtername, $read_write = STREAM_FILTER_READ, $params = array())

Prepend a filter to the chain

boolean
removeFilter(resource $resource, boolean $byindex = false)

Remove a filter, either by resource (handed out from the append or prepend function) or via getting the filter list)

mixed
copy($src, $dest, $context = null, $use_prefix = true, $relative = false)

Copy a file from src to dest

mixed
move($src, $dest, $context = null, $use_prefix = true, $relative = false)

Moves a file

mixed
delete($filename, $context = null, $use_prefix = true, $relative = false)

Delete a file

mixed
upload($src, $dest, $context = null, $use_prefix = true, $relative = false)

Upload a file

boolean
writeFile($filename, $buffer)

All in one Writes a chunk of data to a file

string
_getFilename(string $filename, string $mode, boolean $use_prefix, boolean $relative)

Determine the appropriate 'filename' of a file

File
getFileHandle()

Return the internal file handle

Details

at line 138
JObject __construct(string $writeprefix = '', string $readprefix = '', string $context = array())

Constructor

Parameters

string $writeprefix Prefix of the stream; Note: unlike the JPATH_*, this has a final path seperator!
string $readprefix
string $context

Return Value

JObject

in JObject at line 56
string __toString()

Magic method to convert the object to a string gracefully.

Return Value

string The classname.

in JObject at line 70
mixed def(string $property, mixed $default = null)

Sets a default value if not alreay assigned

Parameters

string $property The name of the property.
mixed $default The default value.

Return Value

mixed

in JObject at line 88
mixed get(string $property, mixed $default = null)

Returns a property of the object or the default value if the property is not set.

Parameters

string $property The name of the property.
mixed $default The default value.

Return Value

mixed The value of the property.

See also

getProperties()

in JObject at line 107
array getProperties(boolean $public = true)

Returns an associative array of object properties.

Parameters

boolean $public If true, returns only the public properties.

Return Value

array

See also

get()

in JObject at line 133
string getError(integer $i = null, boolean $toString = true)

Get the most recent error message.

Parameters

integer $i Option error index.
boolean $toString Indicates if JError objects should return their error message.

Return Value

string Error message

in JObject at line 165
array getErrors()

Return all errors, if any.

Return Value

array Array of error messages or JErrors.

in JObject at line 180
mixed set(string $property, mixed $value = null)

Modifies a property of the object, creating it if it does not already exist.

Parameters

string $property The name of the property.
mixed $value The value of the property to set.

Return Value

mixed Previous value of the property.

in JObject at line 198
boolean setProperties(mixed $properties)

Set the object properties based on a named array/hash.

Parameters

mixed $properties Either an associative array or another object.

Return Value

boolean

See also

set()

in JObject at line 222
void setError(string $error)

Add an error message.

Parameters

string $error Error message.

Return Value

void

in JObject at line 235
string toString() deprecated

deprecated 12.1 Use magic method __toString()

Return Value

string

See also

__toString()

at line 153
void __destruct()

Destructor

Return Value

void

at line 177
boolean open(string $filename, string $mode = 'r', bool $use_include_path = false, resource $context = null, bool $use_prefix = false, bool $relative = false, bool $detectprocessingmode = false)

Generic File Operations

Open a stream with some lazy loading smarts

Parameters

string $filename Filename
string $mode Mode string to use
bool $use_include_path Use the PHP include path
resource $context Context to use when opening
bool $use_prefix Use a prefix to open the file
bool $relative Filename is a relative path (if false, strips JPATH_ROOT to make it relative)
bool $detectprocessingmode Detect the processing method for the file and use the appropriate function to handle output automatically

Return Value

boolean

at line 285
boolean close()

Attempt to close a file handle

Will return false if it failed and true on success

Return Value

boolean

at line 342
boolean eof()

Work out if we're at the end of the file for a stream

Return Value

boolean

at line 387
mixed filesize()

Retrieve the file size of the path

Return Value

mixed

at line 447
mixed gets(integer $length)

Parameters

integer $length

Return Value

mixed

at line 500
mixed read(integer $length)

Read a file

Handles user space streams appropriately otherwise any read will return 8192

Parameters

integer $length Length of data to read

Return Value

mixed

See also

http://php.net/manual/en/function.fread.php

at line 591
boolean seek(integer $offset, integer $whence = SEEK_SET)

Seek the file

Note: the return value is different to that of fseek

Parameters

integer $offset Offset to use when seeking
integer $whence Seek mode to use

Return Value

boolean True on success, false on failure

See also

http://php.net/manual/en/function.fseek.php

at line 638
mixed tell()

Return Value

mixed

at line 697
boolean write(string $string, integer $length, integer $chunk)

File write

Whilst this function accepts a reference, the underlying fwrite will do a copy! This will roughly double the memory allocation for any write you do. Specifying chunked will get around this by only writing in specific chunk sizes. This defaults to 8192 which is a sane number to use most of the time (change the default with JStream::set('chunksize', newsize);) Note: This doesn't support gzip/bzip2 writing like reading does

Parameters

string $string Reference to the string to write
integer $length Length of the string to write
integer $chunk Size of chunks to write in

Return Value

boolean

See also

http://php.net/manual/en/function.fwrite.php

at line 764
boolean chmod(string $filename = '', mixed $mode)

Chmod wrapper

Parameters

string $filename File name
mixed $mode Mode to use

Return Value

boolean

at line 824
array get_meta_data()

Get the stream metadata

Return Value

array header/metadata

See also

http://php.net/manual/en/function.stream-get-meta-data.php

at line 843
mixed _buildContext()

Stream contexts Builds the context from the array

Return Value

mixed

at line 866
void setContextOptions(array $context)

Updates the context to the array

Format is the same as the options for streamcontextcreate

Parameters

array $context Options to create the context with

Return Value

void

See also

http://php.net/stream_context_create

at line 885
void addContextEntry(string $wrapper, string $name, string $value)

Adds a particular options to the context

Parameters

string $wrapper The wrapper to use
string $name The option to set
string $value The value of the option

Return Value

void

See also

http://php.net/stream_context_create Stream Context Creation
http://php.net/manual/en/context.php Context Options for various streams

at line 902
void deleteContextEntry(string $wrapper, string $name)

Deletes a particular setting from a context

Parameters

string $wrapper The wrapper to use
string $name The option to unset

Return Value

void

See also

http://php.net/stream_context_create

at line 932
mixed applyContextToStream()

Applies the current context to the stream

Use this to change the values of the context after you've opened a stream

Return Value

mixed

at line 967
mixed appendFilter($filtername, $read_write = STREAM_FILTER_READ, $params = array())

Stream filters Append a filter to the chain

Parameters

$filtername
$read_write
$params

Return Value

mixed

See also

http://php.net/manual/en/function.stream-filter-append.php

at line 1005
mixed prependFilter($filtername, $read_write = STREAM_FILTER_READ, $params = array())

Prepend a filter to the chain

Parameters

$filtername
$read_write
$params

Return Value

mixed

See also

http://php.net/manual/en/function.stream-filter-prepend.php

at line 1043
boolean removeFilter(resource $resource, boolean $byindex = false)

Remove a filter, either by resource (handed out from the append or prepend function) or via getting the filter list)

Parameters

resource $resource
boolean $byindex

Return Value

boolean Result of operation

at line 1085
mixed copy($src, $dest, $context = null, $use_prefix = true, $relative = false)

Copy a file from src to dest

Parameters

$src
$dest
$context
$use_prefix
$relative

Return Value

mixed

at line 1174
mixed move($src, $dest, $context = null, $use_prefix = true, $relative = false)

Moves a file

Parameters

$src
$dest
$context
$use_prefix
$relative

Return Value

mixed

at line 1223
mixed delete($filename, $context = null, $use_prefix = true, $relative = false)

Delete a file

Parameters

$filename
$context
$use_prefix
$relative

Return Value

mixed

at line 1270
mixed upload($src, $dest, $context = null, $use_prefix = true, $relative = false)

Upload a file

Parameters

$src
$dest
$context
$use_prefix
$relative

Return Value

mixed

at line 1293
boolean writeFile($filename, $buffer)

All in one Writes a chunk of data to a file

Parameters

$filename
$buffer

Return Value

boolean

at line 1318
string _getFilename(string $filename, string $mode, boolean $use_prefix, boolean $relative)

Determine the appropriate 'filename' of a file

Parameters

string $filename Original filename of the file
string $mode Mode string to retrieve the filename
boolean $use_prefix Controls the use of a prefix
boolean $relative Determines if the filename given is relative. Relative paths do not have JPATH_ROOT stripped.

Return Value

string

at line 1352
File getFileHandle()

Return the internal file handle

Return Value

File handler