Permalink
Browse files

HTTP_Download -> HTTP_Download2

  • Loading branch information...
1 parent 55d0331 commit 282645a1c775beef6158299b7c1a6b666e5bd53c @CloCkWeRX CloCkWeRX committed Jan 10, 2012
Showing with 52 additions and 52 deletions.
  1. +42 −42 HTTP/Download2.php
  2. +9 −9 HTTP/Download2/Archive.php
  3. +1 −1 tests/HTTP_Download2Test.php
View
@@ -32,44 +32,44 @@
/**
* Send data as attachment
*/
-define('HTTP_DOWNLOAD_ATTACHMENT', 'attachment');
+define('HTTP_DOWNLOAD2_ATTACHMENT', 'attachment');
/**
* Send data inline
*/
-define('HTTP_DOWNLOAD_INLINE', 'inline');
+define('HTTP_DOWNLOAD2_INLINE', 'inline');
/**#@-**/
/**#@+ Use with HTTP_Download::sendArchive() **/
/**
* Send as uncompressed tar archive
*/
-define('HTTP_DOWNLOAD_TAR', 'TAR');
+define('HTTP_DOWNLOAD2_TAR', 'TAR');
/**
* Send as gzipped tar archive
*/
-define('HTTP_DOWNLOAD_TGZ', 'TGZ');
+define('HTTP_DOWNLOAD2_TGZ', 'TGZ');
/**
* Send as bzip2 compressed tar archive
*/
-define('HTTP_DOWNLOAD_BZ2', 'BZ2');
+define('HTTP_DOWNLOAD2_BZ2', 'BZ2');
/**
* Send as zip archive
*/
-define('HTTP_DOWNLOAD_ZIP', 'ZIP');
+define('HTTP_DOWNLOAD2_ZIP', 'ZIP');
/**#@-**/
/**#@+
* Error constants
*/
-define('HTTP_DOWNLOAD_E_HEADERS_SENT', -1);
-define('HTTP_DOWNLOAD_E_NO_EXT_ZLIB', -2);
-define('HTTP_DOWNLOAD_E_NO_EXT_MMAGIC', -3);
-define('HTTP_DOWNLOAD_E_INVALID_FILE', -4);
-define('HTTP_DOWNLOAD_E_INVALID_PARAM', -5);
-define('HTTP_DOWNLOAD_E_INVALID_RESOURCE', -6);
-define('HTTP_DOWNLOAD_E_INVALID_REQUEST', -7);
-define('HTTP_DOWNLOAD_E_INVALID_CONTENT_TYPE', -8);
-define('HTTP_DOWNLOAD_E_INVALID_ARCHIVE_TYPE', -9);
+define('HTTP_DOWNLOAD2_E_HEADERS_SENT', -1);
+define('HTTP_DOWNLOAD2_E_NO_EXT_ZLIB', -2);
+define('HTTP_DOWNLOAD2_E_NO_EXT_MMAGIC', -3);
+define('HTTP_DOWNLOAD2_E_INVALID_FILE', -4);
+define('HTTP_DOWNLOAD2_E_INVALID_PARAM', -5);
+define('HTTP_DOWNLOAD2_E_INVALID_RESOURCE', -6);
+define('HTTP_DOWNLOAD2_E_INVALID_REQUEST', -7);
+define('HTTP_DOWNLOAD2_E_INVALID_CONTENT_TYPE', -8);
+define('HTTP_DOWNLOAD2_E_INVALID_ARCHIVE_TYPE', -9);
/**#@-**/
// }}}
@@ -278,7 +278,7 @@ function setParams($params)
if (!method_exists($this, $method)) {
return PEAR::raiseError(
"Method '$method' doesn't exist.",
- HTTP_DOWNLOAD_E_INVALID_PARAM
+ HTTP_DOWNLOAD2_E_INVALID_PARAM
);
}
@@ -295,7 +295,7 @@ function setParams($params)
* Set path to file for download
*
* The Last-Modified header will be set to files filemtime(), actually.
- * Returns PEAR_Error (HTTP_DOWNLOAD_E_INVALID_FILE) if file doesn't exist.
+ * Returns PEAR_Error (HTTP_DOWNLOAD2_E_INVALID_FILE) if file doesn't exist.
* Sends HTTP 404 or 403 status if $send_error is set to true.
*
* @access public
@@ -317,7 +317,7 @@ function setFile($file, $send_error = true)
}
return PEAR::raiseError(
"File '$file' not found.",
- HTTP_DOWNLOAD_E_INVALID_FILE
+ HTTP_DOWNLOAD2_E_INVALID_FILE
);
}
if (!is_readable($file)) {
@@ -326,7 +326,7 @@ function setFile($file, $send_error = true)
}
return PEAR::raiseError(
"Cannot read file '$file'.",
- HTTP_DOWNLOAD_E_INVALID_FILE
+ HTTP_DOWNLOAD2_E_INVALID_FILE
);
}
$this->setLastModified(filemtime($file));
@@ -354,7 +354,7 @@ function setData($data = null)
* Set resource for download
*
* The resource handle supplied will be closed after sending the download.
- * Returns a PEAR_Error (HTTP_DOWNLOAD_E_INVALID_RESOURCE) if $handle
+ * Returns a PEAR_Error (HTTP_DOWNLOAD2_E_INVALID_RESOURCE) if $handle
* is no valid resource. Set $handle to null if you want to unset this.
*
* @access public
@@ -383,14 +383,14 @@ function setResource($handle = null)
return PEAR::raiseError(
"Handle '$handle' is no valid resource.",
- HTTP_DOWNLOAD_E_INVALID_RESOURCE
+ HTTP_DOWNLOAD2_E_INVALID_RESOURCE
);
}
/**
* Whether to gzip the download
*
- * Returns a PEAR_Error (HTTP_DOWNLOAD_E_NO_EXT_ZLIB)
+ * Returns a PEAR_Error (HTTP_DOWNLOAD2_E_NO_EXT_ZLIB)
* if ext/zlib is not available/loadable.
*
* @access public
@@ -406,7 +406,7 @@ function setGzip($gzip = false)
if ($gzip && !PEAR::loadExtension('zlib')){
return PEAR::raiseError(
'GZIP compression (ext/zlib) not available.',
- HTTP_DOWNLOAD_E_NO_EXT_ZLIB
+ HTTP_DOWNLOAD2_E_NO_EXT_ZLIB
);
}
$this->gzip = (bool) $gzip;
@@ -480,7 +480,7 @@ function setETag($etag = null)
* you set a very low buffer size that the actual file size may grow
* due to added gzip headers for each sent chunk of the specified size.
*
- * Returns PEAR_Error (HTTP_DOWNLOAD_E_INVALID_PARAM) if $size is not
+ * Returns PEAR_Error (HTTP_DOWNLOAD2_E_INVALID_PARAM) if $size is not
* greater than 0 bytes.
*
* @access public
@@ -496,7 +496,7 @@ function setBufferSize($bytes = 2097152)
if (0 >= $bytes) {
return PEAR::raiseError(
'Buffer size must be greater than 0 bytes ('. $bytes .' given)',
- HTTP_DOWNLOAD_E_INVALID_PARAM);
+ HTTP_DOWNLOAD2_E_INVALID_PARAM);
}
$this->bufferSize = abs($bytes);
return true;
@@ -563,12 +563,12 @@ function setLastModified($last_modified)
* <b>Example:</b>
* <code>
* $HTTP_Download2->setContentDisposition(
- * HTTP_DOWNLOAD_ATTACHMENT,
+ * HTTP_DOWNLOAD2_ATTACHMENT,
* 'download.tgz'
* );
* </code>
*/
- function setContentDisposition( $disposition = HTTP_DOWNLOAD_ATTACHMENT,
+ function setContentDisposition( $disposition = HTTP_DOWNLOAD2_ATTACHMENT,
$file_name = null)
{
$cd = $disposition;
@@ -584,7 +584,7 @@ function setContentDisposition( $disposition = HTTP_DOWNLOAD_ATTACHMENT,
* Set content type of the download
*
* Default content type of the download will be 'application/x-octetstream'.
- * Returns PEAR_Error (HTTP_DOWNLOAD_E_INVALID_CONTENT_TYPE) if
+ * Returns PEAR_Error (HTTP_DOWNLOAD2_E_INVALID_CONTENT_TYPE) if
* $content_type doesn't seem to be valid.
*
* @access public
@@ -600,7 +600,7 @@ function setContentType($content_type = 'application/x-octetstream')
if (!preg_match('/^[a-z]+\w*\/[a-z]+[\w.;= -]*$/', $content_type)) {
return PEAR::raiseError(
"Invalid content type '$content_type' supplied.",
- HTTP_DOWNLOAD_E_INVALID_CONTENT_TYPE
+ HTTP_DOWNLOAD2_E_INVALID_CONTENT_TYPE
);
}
$this->headers['Content-Type'] = $content_type;
@@ -615,12 +615,12 @@ function setContentType($content_type = 'application/x-octetstream')
*
* Returns PEAR_Error if:
* o if PEAR::MIME_Type failed to detect a proper content type
- * (HTTP_DOWNLOAD_E_INVALID_CONTENT_TYPE)
+ * (HTTP_DOWNLOAD2_E_INVALID_CONTENT_TYPE)
* o ext/magic.mime is not installed, or not properly configured
- * (HTTP_DOWNLOAD_E_NO_EXT_MMAGIC)
+ * (HTTP_DOWNLOAD2_E_NO_EXT_MMAGIC)
* o mime_content_type() couldn't guess content type or returned
* a content type considered to be bogus by setContentType()
- * (HTTP_DOWNLOAD_E_INVALID_CONTENT_TYPE)
+ * (HTTP_DOWNLOAD2_E_INVALID_CONTENT_TYPE)
*
* @access public
* @return mixed Returns true on success or PEAR_Error on failure.
@@ -634,26 +634,26 @@ function guessContentType()
if (class_exists('MIME_Type') || @include_once 'MIME/Type.php') {
if (PEAR::isError($mime_type = MIME_Type::autoDetect($this->file))) {
return PEAR::raiseError($mime_type->getMessage(),
- HTTP_DOWNLOAD_E_INVALID_CONTENT_TYPE);
+ HTTP_DOWNLOAD2_E_INVALID_CONTENT_TYPE);
}
return $this->setContentType($mime_type);
}
if (!function_exists('mime_content_type')) {
return PEAR::raiseError(
'This feature requires ext/mime_magic!',
- HTTP_DOWNLOAD_E_NO_EXT_MMAGIC
+ HTTP_DOWNLOAD2_E_NO_EXT_MMAGIC
);
}
if (!is_file(ini_get('mime_magic.magicfile'))) {
return PEAR::raiseError(
'ext/mime_magic is loaded but not properly configured!',
- HTTP_DOWNLOAD_E_NO_EXT_MMAGIC
+ HTTP_DOWNLOAD2_E_NO_EXT_MMAGIC
);
}
if (!$content_type = @mime_content_type($this->file)) {
return PEAR::raiseError(
'Couldn\'t guess content type with mime_content_type().',
- HTTP_DOWNLOAD_E_INVALID_CONTENT_TYPE
+ HTTP_DOWNLOAD2_E_INVALID_CONTENT_TYPE
);
}
return $this->setContentType($content_type);
@@ -663,8 +663,8 @@ function guessContentType()
* Send
*
* Returns PEAR_Error if:
- * o HTTP headers were already sent (HTTP_DOWNLOAD_E_HEADERS_SENT)
- * o HTTP Range was invalid (HTTP_DOWNLOAD_E_INVALID_REQUEST)
+ * o HTTP headers were already sent (HTTP_DOWNLOAD2_E_HEADERS_SENT)
+ * o HTTP Range was invalid (HTTP_DOWNLOAD2_E_INVALID_REQUEST)
*
* @access public
* @return mixed Returns true on success or PEAR_Error on failure.
@@ -680,7 +680,7 @@ function send($autoSetContentDisposition = true)
if (headers_sent()) {
return PEAR::raiseError(
'Headers already sent.',
- HTTP_DOWNLOAD_E_HEADERS_SENT
+ HTTP_DOWNLOAD2_E_HEADERS_SENT
);
}
@@ -786,7 +786,7 @@ function staticSend($params, $guess = false)
* HTTP_Download2::sendArchive(
* 'myArchive.tgz',
* '/var/ftp/pub/mike',
- * HTTP_DOWNLOAD_TGZ,
+ * HTTP_DOWNLOAD2_TGZ,
* '',
* '/var/ftp/pub'
* );
@@ -805,7 +805,7 @@ function staticSend($params, $guess = false)
*/
function sendArchive( $name,
$files,
- $type = HTTP_DOWNLOAD_TGZ,
+ $type = HTTP_DOWNLOAD2_TGZ,
$add_path = '',
$strip_path = '')
{
@@ -1002,7 +1002,7 @@ function getChunks()
// response with a status of 416 (Requested range not satisfiable).
if (!$satisfiable) {
$error = PEAR::raiseError('Error processing range request',
- HTTP_DOWNLOAD_E_INVALID_REQUEST);
+ HTTP_DOWNLOAD2_E_INVALID_REQUEST);
return $error;
}
//$this->sortChunks($parts);
View
@@ -44,7 +44,7 @@ class HTTP_Download2_Archive
* HTTP_Download2_Archive::send(
* 'myArchive.tgz',
* '/var/ftp/pub/mike',
- * HTTP_DOWNLOAD_BZ2,
+ * HTTP_DOWNLOAD2_BZ2,
* '',
* '/var/ftp/pub'
* );
@@ -60,31 +60,31 @@ class HTTP_Download2_Archive
* @param string $add_path path that should be prepended to the files
* @param string $strip_path path that should be stripped from the files
*/
- function send($name, $files, $type = HTTP_DOWNLOAD_TGZ, $add_path = '', $strip_path = '')
+ function send($name, $files, $type = HTTP_DOWNLOAD2_TGZ, $add_path = '', $strip_path = '')
{
$tmp = System::mktemp();
switch ($type = strToUpper($type))
{
- case HTTP_DOWNLOAD_TAR:
+ case HTTP_DOWNLOAD2_TAR:
include_once 'Archive/Tar.php';
$arc = &new Archive_Tar($tmp);
$content_type = 'x-tar';
break;
- case HTTP_DOWNLOAD_TGZ:
+ case HTTP_DOWNLOAD2_TGZ:
include_once 'Archive/Tar.php';
$arc = &new Archive_Tar($tmp, 'gz');
$content_type = 'x-gzip';
break;
- case HTTP_DOWNLOAD_BZ2:
+ case HTTP_DOWNLOAD2_BZ2:
include_once 'Archive/Tar.php';
$arc = &new Archive_Tar($tmp, 'bz2');
$content_type = 'x-bzip2';
break;
- case HTTP_DOWNLOAD_ZIP:
+ case HTTP_DOWNLOAD2_ZIP:
include_once 'Archive/Zip.php';
$arc = &new Archive_Zip($tmp);
$content_type = 'x-zip';
@@ -93,11 +93,11 @@ function send($name, $files, $type = HTTP_DOWNLOAD_TGZ, $add_path = '', $strip_p
default:
return PEAR::raiseError(
'Archive type not supported: ' . $type,
- HTTP_DOWNLOAD_E_INVALID_ARCHIVE_TYPE
+ HTTP_DOWNLOAD2_E_INVALID_ARCHIVE_TYPE
);
}
- if ($type == HTTP_DOWNLOAD_ZIP) {
+ if ($type == HTTP_DOWNLOAD2_ZIP) {
$options = array( 'add_path' => $add_path,
'remove_path' => $strip_path);
if (!$arc->create($files, $options)) {
@@ -115,7 +115,7 @@ function send($name, $files, $type = HTTP_DOWNLOAD_TGZ, $add_path = '', $strip_p
$dl = &new HTTP_Download2(array('file' => $tmp));
$dl->setContentType('application/' . $content_type);
- $dl->setContentDisposition(HTTP_DOWNLOAD_ATTACHMENT, $name);
+ $dl->setContentDisposition(HTTP_DOWNLOAD2_ATTACHMENT, $name);
return $dl->send();
}
}
@@ -78,7 +78,7 @@ function testguessContentType()
{
$h = &new HTTP_Download2(array('file' => dirname(__FILE__) . '/data.txt'));
$e = $h->guessContentType();
- if (PEAR::isError($e) && $e->getCode() != HTTP_DOWNLOAD_E_NO_EXT_MMAGIC) {
+ if (PEAR::isError($e) && $e->getCode() != HTTP_DOWNLOAD2_E_NO_EXT_MMAGIC) {
$this->assertTrue(false, $e->getMessage());
}
unset($h, $e);

0 comments on commit 282645a

Please sign in to comment.