Files
@ 7ec91347b83f
Branch filter:
Location: hot67beta/libraries/joomla/utilities/buffer.php
7ec91347b83f
2.5 KiB
text/x-php
there we go
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 | <?php
/**
* @version $Id:buffer.php 6961 2007-03-15 16:06:53Z tcp $
* @package Joomla.Framework
* @subpackage Utilities
* @copyright Copyright (C) 2005 - 2008 Open Source Matters. All rights reserved.
* @license GNU/GPL, see LICENSE.php
* Joomla! is free software. This version may have been modified pursuant
* to the GNU General Public License, and as distributed it includes or
* is derivative of works licensed under the GNU General Public License or
* other free or open source software licenses.
* See COPYRIGHT.php for copyright notices and details.
*/
/**
* Generic Buffer stream handler
*
* This class provides a generic buffer stream. It can be used to store/retrieve/manipulate
* string buffers with the standard PHP filesystem I/O methods.
*
* @package Joomla.Framework
* @subpackage Utilities
* @since 1.5
*/
class JBuffer
{
/**
* Stream position
* @var int
*/
var $position = 0;
/**
* Buffer name
* @var string
*/
var $name = null;
/**
* Buffer hash
* @var array
*/
var $_buffers = array ();
function stream_open($path, $mode, $options, & $opened_path)
{
$url = parse_url($path);
$this->name = $url["host"];
$this->_buffers[$this->name] = null;
$this->position = 0;
return true;
}
function stream_read($count)
{
$ret = substr($this->_buffers[$this->name], $this->position, $count);
$this->position += strlen($ret);
return $ret;
}
function stream_write($data)
{
$left = substr($this->_buffers[$this->name], 0, $this->position);
$right = substr($this->_buffers[$this->name], $this->position + strlen($data));
$this->_buffers[$this->name] = $left . $data . $right;
$this->position += strlen($data);
return strlen($data);
}
function stream_tell() {
return $this->position;
}
function stream_eof() {
return $this->position >= strlen($this->_buffers[$this->name]);
}
function stream_seek($offset, $whence)
{
switch ($whence)
{
case SEEK_SET :
if ($offset < strlen($this->_buffers[$this->name]) && $offset >= 0) {
$this->position = $offset;
return true;
} else {
return false;
}
break;
case SEEK_CUR :
if ($offset >= 0) {
$this->position += $offset;
return true;
} else {
return false;
}
break;
case SEEK_END :
if (strlen($this->_buffers[$this->name]) + $offset >= 0) {
$this->position = strlen($this->_buffers[$this->name]) + $offset;
return true;
} else {
return false;
}
break;
default :
return false;
}
}
}
// Register the stream
stream_wrapper_register("buffer", "JBuffer");
|