Joomla! Platform 12.1

 Class JStream

Description

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.

Located in /libraries/joomla/filesystem/stream.php (line 31)

Class JObject   (Subpackage Object)

Class JStream   (Subpackage FileSystem--)
Variable Summary
Variable integer $chunksize
Variable integer $dirmode
Variable array $fh
Variable integer $filemode
Variable string $filename
Variable integer $filesize
Variable array $filters
Variable string $readprefix
Variable string $writeprefix
Method Summary
Constructor JStream __construct ([string $writeprefix = ''], [string $readprefix = ''], [array $context = array()])
Destructor void __destruct ()
Method void addContextEntry (string $wrapper, string $name, string $value)
Method mixed appendFilter (string $filtername, [integer $read_write = STREAM_FILTER_READ], [array $params = array()])
Method boolean chmod ([string $filename = ''], [mixed $mode = 0])
Method boolean close ()
Method mixed copy (string $src, string $dest, [resource $context = null], [boolean $use_prefix = true], [boolean $relative = false])
Method mixed delete (string $filename, [resource $context = null], [boolean $use_prefix = true], [boolean $relative = false])
Method void deleteContextEntry (string $wrapper, string $name)
Method boolean eof ()
Method mixed filesize ()
Method File getFileHandle ()
Method mixed gets ([integer $length = 0])
Method array get_meta_data ()
Method mixed move (string $src, string $dest, [resource $context = null], [boolean $use_prefix = true], [boolean $relative = false])
Method boolean open (string $filename, [string $mode = 'r'], [boolean $use_include_path = false], [resource $context = null], [boolean $use_prefix = false], [boolean $relative = false], [boolean $detectprocessingmode = false])
Method mixed prependFilter (string $filtername, [integer $read_write = STREAM_FILTER_READ], [array $params = array()])
Method mixed read ([integer $length = 0])
Method boolean removeFilter (resource &$resource, [boolean $byindex = false])
Method boolean seek (integer $offset, [integer $whence = SEEK_SET])
Method void setContextOptions (array $context)
Method mixed tell ()
Method mixed upload (string $src, string $dest, [resource $context = null], [boolean $use_prefix = true], [boolean $relative = false])
Method boolean write (string &$string, [integer $length = 0], [integer $chunk = 0])
Method boolean writeFile (string $filename, string &$buffer)
Method mixed _buildContext ()
Method string _getFilename (string $filename, string $mode, boolean $use_prefix, boolean $relative)
Variables
integer $chunksize = 8192 (line 53)

Default Chunk Size

  • since: 11.1
  • access: protected
$context = null (line 112)

Context to use when opening the connection

  • since: 12.1
  • access: protected
$contextOptions (line 119)

Context options; used to rebuild the context

  • since: 12.1
  • access: protected
integer $dirmode = 0755 (line 46)

Directory Mode

  • since: 11.1
  • access: protected
array $fh (line 98)

File Handle

  • since: 12.1
  • access: protected
integer $filemode = 0644 (line 39)

File Mode

  • since: 11.1
  • access: protected
string $filename (line 60)

Filename

  • since: 11.1
  • access: protected
integer $filesize (line 105)

File size

  • since: 12.1
  • access: protected
array $filters = array() (line 91)

Filters applied to the current stream

  • since: 11.1
  • access: protected
$openmode (line 126)

The mode under which the file was opened

  • since: 12.1
  • access: protected
string $processingmethod = 'f' (line 84)

Read Processing method

  • var: gz, bz, f If a scheme is detected, fopen will be defaulted To use compression with a network stream use a filter
  • since: 11.1
  • access: protected
string $readprefix (line 74)

Prefix of the connection for reading

  • since: 11.1
  • access: protected
string $writeprefix (line 67)

Prefix of the connection for writing

  • since: 11.1
  • access: protected

Inherited Variables

Inherited from JObject

Variable JObject::$_errors
Methods
Constructor __construct (line 137)

Constructor

  • since: 11.1
  • access: public
JStream __construct ([string $writeprefix = ''], [string $readprefix = ''], [array $context = array()])
  • string $writeprefix: Prefix of the stream (optional). Unlike the JPATH_*, this has a final path separator!
  • string $readprefix: The read prefix (optional).
  • array $context: The context options (optional).

Redefinition of:
JObject::__construct()
Class constructor, overridden in descendant classes.
Destructor __destruct (line 150)

Destructor

  • since: 11.1
  • access: public
void __destruct ()
addContextEntry (line 952)

Adds a particular options to the context

void addContextEntry (string $wrapper, string $name, string $value)
  • string $wrapper: The wrapper to use
  • string $name: The option to set
  • string $value: The value of the option
appendFilter (line 1039)

Stream filters Append a filter to the chain

mixed appendFilter (string $filtername, [integer $read_write = STREAM_FILTER_READ], [array $params = array()])
  • string $filtername: The key name of the filter.
  • integer $read_write: Optional. Defaults to STREAM_FILTER_READ.
  • array $params: An array of params for the stream_filter_append call.
applyContextToStream (line 1002)

Applies the current context to the stream

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

  • since: 11.1
  • access: public
mixed applyContextToStream ()
chmod (line 822)

Chmod wrapper

  • since: 11.1
  • access: public
boolean chmod ([string $filename = ''], mixed $mode)
  • string $filename: File name.
  • mixed $mode: Mode to use.
close (line 294)

Attempt to close a file handle

Will return false if it failed and true on success If the file is not open the system will return true, this function destroys the file handle as well

  • since: 11.1
  • access: public
boolean close ()
copy (line 1163)

Copy a file from src to dest

  • since: 11.1
  • access: public
mixed copy (string $src, string $dest, [resource $context = null], [boolean $use_prefix = true], [boolean $relative = false])
  • string $src: The file path to copy from.
  • string $dest: The file path to copy to.
  • resource $context: A valid context resource (optional) created with stream_context_create.
  • boolean $use_prefix: Controls the use of a prefix (optional).
  • boolean $relative: Determines if the filename given is relative. Relative paths do not have JPATH_ROOT stripped.
delete (line 1277)

Delete a file

  • since: 11.1
  • access: public
mixed delete (string $filename, [resource $context = null], [boolean $use_prefix = true], [boolean $relative = false])
  • string $filename: The file path to delete.
  • resource $context: A valid context resource (optional) created with stream_context_create.
  • boolean $use_prefix: Controls the use of a prefix (optional).
  • boolean $relative: Determines if the filename given is relative. Relative paths do not have JPATH_ROOT stripped.
deleteContextEntry (line 969)

Deletes a particular setting from a context

void deleteContextEntry (string $wrapper, string $name)
  • string $wrapper: The wrapper to use
  • string $name: The option to unset
eof (line 356)

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

  • since: 11.1
  • access: public
boolean eof ()
filesize (line 402)

Retrieve the file size of the path

  • since: 11.1
  • access: public
mixed filesize ()
getFileHandle (line 1418)

Return the internal file handle

  • return: handler
  • since: 11.1
  • access: public
File getFileHandle ()
gets (line 473)

Get a line from the stream source.

  • since: 11.1
  • access: public
mixed gets (integer $length)
  • integer $length: The number of bytes (optional) to read.
get_meta_data (line 888)

Get the stream metadata

array get_meta_data ()
move (line 1224)

Moves a file

  • since: 11.1
  • access: public
mixed move (string $src, string $dest, [resource $context = null], [boolean $use_prefix = true], [boolean $relative = false])
  • string $src: The file path to move from.
  • string $dest: The file path to move to.
  • resource $context: A valid context resource (optional) created with stream_context_create.
  • boolean $use_prefix: Controls the use of a prefix (optional).
  • boolean $relative: Determines if the filename given is relative. Relative paths do not have JPATH_ROOT stripped.
open (line 177)

Generic File Operations

Open a stream with some lazy loading smarts

  • since: 11.1
  • access: public
boolean open (string $filename, [string $mode = 'r'], [boolean $use_include_path = false], [resource $context = null], [boolean $use_prefix = false], [boolean $relative = false], [boolean $detectprocessingmode = false])
  • string $filename: Filename
  • string $mode: Mode string to use
  • boolean $use_include_path: Use the PHP include path
  • resource $context: Context to use when opening
  • boolean $use_prefix: Use a prefix to open the file
  • boolean $relative: Filename is a relative path (if false, strips JPATH_ROOT to make it relative)
  • boolean $detectprocessingmode: Detect the processing method for the file and use the appropriate function to handle output automatically
prependFilter (line 1080)

Prepend a filter to the chain

mixed prependFilter (string $filtername, [integer $read_write = STREAM_FILTER_READ], [array $params = array()])
  • string $filtername: The key name of the filter.
  • integer $read_write: Optional. Defaults to STREAM_FILTER_READ.
  • array $params: An array of params for the stream_filter_prepend call.
read (line 530)

Read a file

Handles user space streams appropriately otherwise any read will return 8192

mixed read (integer $length)
  • integer $length: Length of data to read
removeFilter (line 1121)

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

  • return: Result of operation
  • since: 11.1
  • access: public
boolean removeFilter (resource &$resource, [boolean $byindex = false])
  • resource &$resource: The resource.
  • boolean $byindex: The index of the filter.
seek (line 633)

Seek the file

Note: the return value is different to that of fseek

boolean seek (integer $offset, [integer $whence = SEEK_SET])
  • integer $offset: Offset to use when seeking.
  • integer $whence: Seek mode to use.
setContextOptions (line 933)

Updates the context to the array

Format is the same as the options for stream_context_create

void setContextOptions (array $context)
  • array $context: Options to create the context with
tell (line 686)

Returns the current position of the file read/write pointer.

  • since: 11.1
  • access: public
mixed tell ()
upload (line 1328)

Upload a file

  • since: 11.1
  • access: public
mixed upload (string $src, string $dest, [resource $context = null], [boolean $use_prefix = true], [boolean $relative = false])
  • string $src: The file path to copy from (usually a temp folder).
  • string $dest: The file path to copy to.
  • resource $context: A valid context resource (optional) created with stream_context_create.
  • boolean $use_prefix: Controls the use of a prefix (optional).
  • boolean $relative: Determines if the filename given is relative. Relative paths do not have JPATH_ROOT stripped.
write (line 748)

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

boolean write (string &$string, integer $length, integer $chunk)
  • string &$string: Reference to the string to write.
  • integer $length: Length of the string to write.
  • integer $chunk: Size of chunks to write in.
writeFile (line 1353)

Writes a chunk of data to a file.

  • since: 11.1
  • access: public
boolean writeFile (string $filename, string &$buffer)
  • string $filename: The file name.
  • string &$buffer: The data to write to the file.
_buildContext (line 908)

Stream contexts Builds the context from the array

  • since: 11.1
  • access: public
mixed _buildContext ()
_getFilename (line 1379)

Determine the appropriate 'filename' of a file

  • since: 11.1
  • access: public
string _getFilename (string $filename, string $mode, boolean $use_prefix, boolean $relative)
  • 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.

Inherited Methods

Inherited From JObject

 JObject::__construct()
 JObject::def()
 JObject::get()
 JObject::getError()
 JObject::getErrors()
 JObject::getProperties()
 JObject::set()
 JObject::setError()
 JObject::setProperties()
 JObject::__toString()
/html>