Skip to content

Commit

Permalink
Merge pull request #13 from yarroslav/master
Browse files Browse the repository at this point in the history
Add option not to use zip compression
  • Loading branch information
Synchro committed Apr 23, 2014
2 parents 7132cb9 + f436caa commit b45b1e4
Showing 1 changed file with 30 additions and 10 deletions.
40 changes: 30 additions & 10 deletions UAS/Parser.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,12 @@ class Parser
* @type bool
*/
protected $doDownloads = true;

/**
* Should this instance use zip compression while downloads
* Useful if use mbstring.func_overload
* @type bool
*/
protected $useZipDownloads = true;
/**
* URL to fetch the full data file from.
* @type string
Expand Down Expand Up @@ -452,18 +457,19 @@ protected function getContents($url, $timeout = 300)
$starttime = microtime(true);
// use fopen
if (ini_get('allow_url_fopen')) {
$stream_options = array(
'http' => array(
'timeout' => $timeout
)
);
if ($this->useZipDownloads) {
$stream_options['http']['header'] = "Accept-Encoding: gzip\r\n";
}
$fp = @fopen(
$url,
'rb',
false,
stream_context_create(
array(
'http' => array(
'timeout' => $timeout,
'header' => "Accept-Encoding: gzip\r\n"
)
)
)
stream_context_create($stream_options)
);
if (is_resource($fp)) {
$data = stream_get_contents($fp);
Expand Down Expand Up @@ -513,9 +519,15 @@ protected function getContents($url, $timeout = 300)
CURLOPT_TIMEOUT => $timeout,
CURLOPT_CONNECTTIMEOUT => $timeout,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => 'gzip'
)
);
if ($this->useZipDownloads) {
curl_setopt(
$ch,
CURLOPT_ENCODING,
'gzip'
);
}
$data = curl_exec($ch);
if ($data !== false and curl_errno($ch) == 0) {
$this->debug(
Expand Down Expand Up @@ -559,6 +571,14 @@ public function setCacheDir($cache_dir)
return true;
}

/**
* Set use zip compression while downloading updates.
* @param bool $use
*/
public function setUseZipDownloads($use) {
$this->useZipDownloads = (bool)$use;
}

/**
* Get the cache directory
* @return string
Expand Down

0 comments on commit b45b1e4

Please sign in to comment.