Add Zend_Media_Id3v2 class proposal
git-svn-id: http://php-reader.googlecode.com/svn/branches/zend@153 51a70ab9-7547-0410-9469-37e369ee0574
This commit is contained in:
@@ -50,7 +50,8 @@ class Zend_Io_FileReader extends Zend_Io_Reader
|
||||
if (!file_exists($filename) || !is_readable($filename) ||
|
||||
($fd = fopen($filename, $mode)) === false) {
|
||||
require_once('Zend/Io/Exception.php');
|
||||
throw new Zend_Io_Exception('Unable to open file for reading: ' . $filename);
|
||||
throw new Zend_Io_Exception
|
||||
('Unable to open file for reading: ' . $filename);
|
||||
}
|
||||
parent::__construct($fd);
|
||||
}
|
||||
|
||||
@@ -50,7 +50,8 @@ class Zend_Io_FileWriter extends Zend_Io_Writer
|
||||
$mode = file_exists($filename) ? 'r+b' : 'wb';
|
||||
if (($fd = fopen($filename, $mode)) === false) {
|
||||
require_once('Zend/Io/Exception.php');
|
||||
throw new Zend_Io_Exception('Unable to open file for writing: ' . $filename);
|
||||
throw new Zend_Io_Exception
|
||||
('Unable to open file for writing: ' . $filename);
|
||||
}
|
||||
parent::__construct($fd);
|
||||
}
|
||||
|
||||
@@ -69,7 +69,8 @@ class Zend_Io_Reader
|
||||
if (!is_resource($fd) ||
|
||||
!in_array(get_resource_type($fd), array('stream'))) {
|
||||
require_once('Zend/Io/Exception.php');
|
||||
throw new Zend_Io_Exception('Invalid resource type (only resources of type stream are supported)');
|
||||
throw new Zend_Io_Exception
|
||||
('Invalid resource type (only resources of type stream are supported)');
|
||||
}
|
||||
|
||||
$this->_fd = $fd;
|
||||
@@ -497,7 +498,8 @@ class Zend_Io_Reader
|
||||
* @throws Zend_Io_Exception if <var>length</var> attribute is negative or
|
||||
* if an I/O error occurs
|
||||
*/
|
||||
public final function readString16($length, &$order = null, $trimOrder = false)
|
||||
public final function readString16
|
||||
($length, &$order = null, $trimOrder = false)
|
||||
{
|
||||
$value = $this->read($length);
|
||||
|
||||
|
||||
@@ -40,23 +40,42 @@ class Zend_Io_StringReader extends Zend_Io_Reader
|
||||
* Constructs the Zend_Io_StringReader class with given source string.
|
||||
*
|
||||
* @param string $data The string to use as the source.
|
||||
* @param integer $length If the <var>length</var> argument is given,
|
||||
* reading will stop after <var>length</var> bytes have been read or
|
||||
* the end of string is reached, whichever comes first.
|
||||
* @throws Zend_Io_Exception if an I/O error occurs
|
||||
*/
|
||||
public function __construct($data)
|
||||
public function __construct($data, $length = null)
|
||||
{
|
||||
if (($this->_fd = fopen('php://memory', 'w+b')) === false) {
|
||||
require_once('Zend/Io/Exception.php');
|
||||
throw new Zend_Io_Exception('Unable to open php://memory stream');
|
||||
}
|
||||
if ($data !== null && is_string($data)) {
|
||||
if (($this->_size = fwrite($this->_fd, $data, $tagSize)) === false) {
|
||||
if ($length === null) {
|
||||
$length = strlen($data);
|
||||
}
|
||||
if (($this->_size = fwrite($this->_fd, $data, $length)) === false) {
|
||||
require_once('Zend/Io/Exception.php');
|
||||
throw new Zend_Io_Exception('Unable to write data to php://memory stream');
|
||||
throw new Zend_Io_Exception
|
||||
('Unable to write data to php://memory stream');
|
||||
}
|
||||
fseek($this->_fd, 0);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the string representation of this class.
|
||||
*/
|
||||
public function toString()
|
||||
{
|
||||
$offset = $this->getOffset();
|
||||
$this->setOffset(0);
|
||||
$data = $this->read($this->getSize());
|
||||
$this->setOffset($offset);
|
||||
return $data;
|
||||
}
|
||||
|
||||
/**
|
||||
* Closes the file descriptor.
|
||||
*/
|
||||
|
||||
@@ -39,24 +39,43 @@ class Zend_Io_StringWriter extends Zend_Io_Writer
|
||||
/**
|
||||
* Constructs the Zend_Io_StringWriter class with given source string.
|
||||
*
|
||||
* @param string $data The string to use as the source.
|
||||
* @param string $data The string to use as the source.
|
||||
* @param integer $length If the <var>length</var> argument is given,
|
||||
* reading will stop after <var>length</var> bytes have been read or
|
||||
* the end of string is reached, whichever comes first.
|
||||
* @throws Zend_Io_Exception if an I/O error occurs
|
||||
*/
|
||||
public function __construct($data = null)
|
||||
public function __construct($data = null, $length = null)
|
||||
{
|
||||
if (($this->_fd = fopen('php://memory', 'w+b')) === false) {
|
||||
require_once('Zend/Io/Exception.php');
|
||||
throw new Zend_Io_Exception('Unable to open php://memory stream');
|
||||
}
|
||||
if ($data !== null && is_string($data)) {
|
||||
if (($this->_size = fwrite($this->_fd, $data, $tagSize)) === false) {
|
||||
if ($length === null) {
|
||||
$length = strlen($data);
|
||||
}
|
||||
if (($this->_size = fwrite($this->_fd, $data, $length)) === false) {
|
||||
require_once('Zend/Io/Exception.php');
|
||||
throw new Zend_Io_Exception('Unable to write data to php://memory stream');
|
||||
throw new Zend_Io_Exception
|
||||
('Unable to write data to php://memory stream');
|
||||
}
|
||||
fseek($this->_fd, 0);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the string representation of this class.
|
||||
*/
|
||||
public function toString()
|
||||
{
|
||||
$offset = $this->getOffset();
|
||||
$this->setOffset(0);
|
||||
$data = fread($this->getFileDescriptor(), $this->getSize());
|
||||
$this->setOffset($offset);
|
||||
return $data;
|
||||
}
|
||||
|
||||
/**
|
||||
* Closes the file descriptor.
|
||||
*/
|
||||
|
||||
@@ -67,9 +67,10 @@ class Zend_Io_Writer
|
||||
public function __construct($fd)
|
||||
{
|
||||
if (!is_resource($fd) ||
|
||||
!in_array(get_resource_type($fd), array('stream'))) {
|
||||
!in_array(get_resource_type($fd), array('stream'))) {
|
||||
require_once('Zend/Io/Exception.php');
|
||||
throw new Zend_Io_Exception('Invalid resource type (only resources of type stream are supported)');
|
||||
throw new Zend_Io_Exception
|
||||
('Invalid resource type (only resources of type stream are supported)');
|
||||
}
|
||||
|
||||
$this->_fd = $fd;
|
||||
@@ -174,7 +175,11 @@ class Zend_Io_Writer
|
||||
require_once('Zend/Io/Exception.php');
|
||||
throw new Zend_Io_Exception('Cannot operate on a closed stream');
|
||||
}
|
||||
fwrite($this->_fd, $value, $length === null ? strlen($value) : $length);
|
||||
if ($length === null) {
|
||||
$length = strlen($value);
|
||||
}
|
||||
fwrite($this->_fd, $value, $length);
|
||||
$this->_size += $length;
|
||||
return $this;
|
||||
}
|
||||
|
||||
@@ -197,7 +202,7 @@ class Zend_Io_Writer
|
||||
* @return Zend_Io_Writer
|
||||
* @throws Zend_Io_Exception if the stream is closed
|
||||
*/
|
||||
public final function writeUInt8()
|
||||
public final function writeUInt8($value)
|
||||
{
|
||||
return $this->write(pack('C*', $value));
|
||||
}
|
||||
@@ -223,7 +228,7 @@ class Zend_Io_Writer
|
||||
*/
|
||||
public final function writeInt16LE($value)
|
||||
{
|
||||
if ($this->_isBigEndian()) {
|
||||
if ($this->_isLittleEndian()) {
|
||||
return $this->write(strrev($this->_toInt16($value)));
|
||||
} else {
|
||||
return $this->write($this->_toInt16($value));
|
||||
@@ -240,7 +245,7 @@ class Zend_Io_Writer
|
||||
*/
|
||||
public final function writeInt16BE($value)
|
||||
{
|
||||
if ($this->_isLittleEndian()) {
|
||||
if ($this->_isBigEndian()) {
|
||||
return $this->write(strrev($this->_toInt16($value)));
|
||||
} else {
|
||||
return $this->write($this->_toInt16($value));
|
||||
@@ -294,7 +299,7 @@ class Zend_Io_Writer
|
||||
*/
|
||||
public final function writeInt32LE($value)
|
||||
{
|
||||
if ($this->_isBigEndian()) {
|
||||
if ($this->_isLittleEndian()) {
|
||||
return $this->write(strrev($this->_toInt32($value)));
|
||||
} else {
|
||||
return $this->write($this->_toInt32($value));
|
||||
@@ -311,7 +316,7 @@ class Zend_Io_Writer
|
||||
*/
|
||||
public final function writeInt32BE($value)
|
||||
{
|
||||
if ($this->_isLittleEndian()) {
|
||||
if ($this->_isBigEndian()) {
|
||||
return $this->write(strrev($this->_toInt32($value)));
|
||||
} else {
|
||||
return $this->write($this->_toInt32($value));
|
||||
@@ -354,7 +359,8 @@ class Zend_Io_Writer
|
||||
*/
|
||||
public final function writeInt64LE($value)
|
||||
{
|
||||
return $this->write(pack('V*', $value & 0xffffffff, $value / (0xffffffff+1)));
|
||||
return $this->write
|
||||
(pack('V*', $value & 0xffffffff, $value / (0xffffffff+1)));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -367,7 +373,8 @@ class Zend_Io_Writer
|
||||
*/
|
||||
public final function writeInt64BE($value)
|
||||
{
|
||||
return $this->write(pack('N*', $value / (0xffffffff+1), $value & 0xffffffff));
|
||||
return $this->write
|
||||
(pack('N*', $value / (0xffffffff+1), $value & 0xffffffff));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -391,7 +398,7 @@ class Zend_Io_Writer
|
||||
*/
|
||||
public final function writeFloatLE($value)
|
||||
{
|
||||
if ($this->_isBigEndian()) {
|
||||
if ($this->_isLittleEndian()) {
|
||||
return $this->write(strrev($this->_toFloat($value)));
|
||||
} else {
|
||||
return $this->write($this->_toFloat($value));
|
||||
@@ -408,7 +415,7 @@ class Zend_Io_Writer
|
||||
*/
|
||||
public final function writeFloatBE($value)
|
||||
{
|
||||
if ($this->_isLittleEndian()) {
|
||||
if ($this->_isBigEndian()) {
|
||||
return $this->write(strrev($this->_toFloat($value)));
|
||||
} else {
|
||||
return $this->write($this->_toFloat($value));
|
||||
|
||||
Reference in New Issue
Block a user