Example #1
0
 public function animetitlesUpdate()
 {
     $pdo = $this->pdo;
     $lastUpdate = $pdo->queryOneRow('SELECT max(unixtime) as utime FROM animetitles');
     if (isset($lastUpdate['utime']) && time() - $lastUpdate['utime'] < 604800) {
         if ($this->echooutput) {
             echo "\n";
             echo $this->c->info("Last update occurred less than 7 days ago, skipping full dat file update.\n\n");
         }
         return;
     }
     if ($this->echooutput) {
         echo $this->c->header("Updating animetitles by grabbing full dat AniDB dump.\n\n");
     }
     $zh = gzopen('http://anidb.net/api/anime-titles.dat.gz', 'r');
     preg_match_all('/(\\d+)\\|\\d\\|.+\\|(.+)/', gzread($zh, '10000000'), $animetitles);
     if (!$animetitles) {
         return false;
     }
     $pdo->queryExec('DELETE FROM animetitles WHERE anidbid IS NOT NULL');
     if ($this->echooutput) {
         echo $this->c->header("Total of " . count($animetitles[1]) . " titles to add\n\n");
     }
     for ($loop = 0; $loop < count($animetitles[1]); $loop++) {
         $pdo->queryInsert(sprintf('INSERT IGNORE INTO animetitles (anidbid, title, unixtime) VALUES (%d, %s, %d)', $animetitles[1][$loop], $pdo->escapeString(html_entity_decode($animetitles[2][$loop], ENT_QUOTES, 'UTF-8')), time()));
     }
     if ($loop % 2500 == 0 && $this->echooutput) {
         echo $this->c->header("Completed Processing " . $loop . " titles.\n\n");
     }
     gzclose($zh);
     if ($this->echooutput) {
         echo $this->c->header("Completed animetitles update.\n\n");
     }
 }
Example #2
0
 public function readCompressedSample($filename)
 {
     $fp = gzopen('test/samples/' . $filename, 'r') or die("can't open: {$php_errormsg}");
     $content = gzread($fp, 128000);
     gzclose($fp);
     return $content;
 }
Example #3
0
	public function extract($archive="", $outputDir = "")
	{
		$gzh = gzopen($archive, 'r') or die("Could not open $archive");
		if(!is_dir($outputDir))
		{
			mkdir($outputDir, 0700, true) or die("Could not create a $outputDir directory");
		}
		$_archive = str_ireplace('.tgz', '.gz', $archive);
		$tar_path = basename($_archive, '.gz');
		$lchar = substr($outputDir, -1);
		if('/' == $lchar OR '\\' == $lchar)
		{
			$tar_path = $outputDir.$tar_path;
		} else {
			$tar_path = $outputDir."/".$tar_path;
		}
		$fh = fopen($tar_path, "w");
		while(!feof($gzh))
		{
			$cstr = gzread($gzh, 4096);
			fwrite($fh, $cstr);
		}
		bzclose($gzh);
		fclose($fh);
		$this->tarHandler->extract($tar_path, $outputDir);
		echo "<font color=\"green\">Sucessfull!</font>";
	}
function backwpup_read_logheader($logfile)
{
    $headers = array("backwpup_version" => "version", "backwpup_logtime" => "logtime", "backwpup_errors" => "errors", "backwpup_warnings" => "warnings", "backwpup_jobid" => "jobid", "backwpup_jobname" => "name", "backwpup_jobtype" => "type", "backwpup_jobruntime" => "runtime", "backwpup_backupfilesize" => "backupfilesize");
    if (!is_readable($logfile)) {
        return false;
    }
    //Read file
    if (substr($logfile, -3) == ".gz") {
        $fp = gzopen($logfile, 'r');
        $file_data = gzread($fp, 1536);
        // Pull only the first 1,5kiB of the file in.
        gzclose($fp);
    } else {
        $fp = fopen($logfile, 'r');
        $file_data = fread($fp, 1536);
        // Pull only the first 1,5kiB of the file in.
        fclose($fp);
    }
    //get data form file
    foreach ($headers as $keyword => $field) {
        preg_match('/(<meta name="' . $keyword . '" content="(.*)" \\/>)/i', $file_data, $content);
        if (!empty($content)) {
            $joddata[$field] = $content[2];
        } else {
            $joddata[$field] = '';
        }
    }
    if (empty($joddata['logtime'])) {
        $joddata['logtime'] = filectime($logfile);
    }
    return $joddata;
}
Example #5
0
 protected function __parseLog($file)
 {
     $items = array();
     $last = null;
     if (is_readable($file)) {
         header('content-type: text/plain');
         if (preg_match('/.gz$/', $file)) {
             $handle = gzopen($file, "r");
             $data = gzread($handle, Symphony::Configuration()->get('maxsize', 'log'));
             gzclose($handle);
         } else {
             $data = file_get_contents($file);
         }
         $lines = explode(PHP_EOL, $data);
         // Skip log info:
         while (count($lines)) {
             $line = trim(array_shift($lines));
             if ($line == '--------------------------------------------') {
                 break;
             }
         }
         // Create items:
         foreach ($lines as $line) {
             preg_match('/^(.*?) > (.*)/', trim($line), $matches);
             // New entry:
             if (count($matches) == 3) {
                 $message = htmlentities($matches[2]);
                 $items[] = (object) array('timestamp' => DateTimeObj::get(__SYM_DATETIME_FORMAT__, strtotime($matches[1])), 'message' => $message);
             }
         }
         // Reverse order:
         $items = array_reverse($items);
     }
     return $items;
 }
 public static function update_database()
 {
     set_time_limit(0);
     $outFile = self::get_upload_file_path();
     // for download_url()
     require_once ABSPATH . 'wp-admin/includes/file.php';
     $tmpFile = \download_url(self::SOURCE_URL);
     if (is_wp_error($tmpFile)) {
         die($tmpFile->get_error_message());
     }
     $zh = gzopen($tmpFile, 'rb');
     $h = fopen($outFile, 'wb');
     if (!$zh) {
         die('Downloaded file could not be opened for reading.');
     }
     if (!$h) {
         die(sprintf('Database could not be written (%s).', $outFile));
     }
     while (!gzeof($zh)) {
         fwrite($h, gzread($zh, 4096));
     }
     gzclose($zh);
     fclose($h);
     unlink($tmpFile);
     if (!self::is_db_valid()) {
         die(sprintf('Checksum does not match (%s).', $outFile));
     }
 }
Example #7
0
 public function animetitlesUpdate()
 {
     $db = new DB();
     $lastUpdate = $db->queryOneRow("SELECT unixtime AS utime FROM animetitles LIMIT 1");
     if (isset($lastUpdate['utime']) && time() - $lastUpdate['utime'] < 604800) {
         return;
     }
     if ($this->echooutput) {
         echo "Updating animetitles.";
     }
     $zh = gzopen('http://anidb.net/api/animetitles.dat.gz', 'r');
     preg_match_all('/(\\d+)\\|\\d\\|.+\\|(.+)/', gzread($zh, '10000000'), $animetitles);
     if (!$animetitles) {
         return false;
     }
     if ($this->echooutput) {
         echo ".";
     }
     $db->query("DELETE FROM animetitles WHERE anidbID IS NOT NULL");
     for ($i = 0; $i < count($animetitles[1]); $i++) {
         $db->queryInsert(sprintf("INSERT INTO animetitles (anidbID, title, unixtime) VALUES (%d, %s, %d)", $animetitles[1][$i], $db->escapeString(html_entity_decode($animetitles[2][$i], ENT_QUOTES, 'UTF-8')), time()));
     }
     $db = NULL;
     gzclose($zh);
     if ($this->echooutput) {
         echo " done.\n";
     }
 }
Example #8
0
function geoip_detect_update()
{
    $download_url = 'http://geolite.maxmind.com/download/geoip/database/GeoLiteCity.dat.gz';
    $outFile = geoip_detect_get_database_upload_filename();
    // Download
    $tmpFile = download_url($download_url);
    if (is_wp_error($tmpFile)) {
        return $tmpFile->get_error_message();
    }
    // Ungzip File
    $zh = gzopen($tmpFile, 'r');
    $h = fopen($outFile, 'w');
    if (!$zh) {
        return __('Downloaded file could not be opened for reading.', 'geoip-detect');
    }
    if (!$h) {
        return sprintf(__('Database could not be written (%s).', 'geoip-detect'), $outFile);
    }
    while (($string = gzread($zh, 4096)) != false) {
        fwrite($h, $string, strlen($string));
    }
    gzclose($zh);
    fclose($h);
    //unlink($tmpFile);
    return true;
}
 /**
  * updates the GeoIP database file
  * works only if directory geoip has rights 777, set it in ftp client
  */
 function updateGeoIpFile()
 {
     global $cpd_path;
     // set directory mode
     @chmod($cpd_path . '/geoip', 0777);
     // function checks
     if (!ini_get('allow_url_fopen')) {
         return 'Sorry, <code>allow_url_fopen</code> is disabled!';
     }
     if (!function_exists('gzopen')) {
         return __('Sorry, necessary functions (zlib) not installed or enabled in php.ini.', 'cpd');
     }
     $gzfile = 'http://geolite.maxmind.com/download/geoip/database/GeoLiteCountry/GeoIP.dat.gz';
     $file = $cpd_path . '/geoip/GeoIP.dat';
     // get remote file
     $h = gzopen($gzfile, 'rb');
     $content = gzread($h, 1500000);
     fclose($h);
     // delete local file
     if (is_file($file)) {
         unlink($file);
     }
     // file deleted?
     $del = is_file($file) ? 0 : 1;
     // write new locale file
     $h = fopen($file, 'wb');
     fwrite($h, $content);
     fclose($h);
     @chmod($file, 0777);
     if (is_file($file) && $del) {
         return __('New GeoIP database installed.', 'cpd');
     } else {
         return __('Sorry, an error occurred. Try again or check the access rights of directory "geoip" is 777.', 'cpd');
     }
 }
Example #10
0
function geoip_detect_update()
{
    // TODO: Currently cron is scheduled but not executed. Remove scheduling.
    if (get_option('geoip-detect-source') != 'auto') {
        return;
    }
    $download_url = 'http://geolite.maxmind.com/download/geoip/database/GeoLite2-City.mmdb.gz';
    $download_url = apply_filters('geoip_detect2_download_url', $download_url);
    $outFile = geoip_detect_get_database_upload_filename();
    // Download
    $tmpFile = download_url($download_url);
    if (is_wp_error($tmpFile)) {
        return $tmpFile->get_error_message();
    }
    // Ungzip File
    $zh = gzopen($tmpFile, 'r');
    $h = fopen($outFile, 'w');
    if (!$zh) {
        return __('Downloaded file could not be opened for reading.', 'geoip-detect');
    }
    if (!$h) {
        return sprintf(__('Database could not be written (%s).', 'geoip-detect'), $outFile);
    }
    while (($string = gzread($zh, 4096)) != false) {
        fwrite($h, $string, strlen($string));
    }
    gzclose($zh);
    fclose($h);
    unlink($tmpFile);
    return true;
}
 function wp_all_import_get_gz($filename, $use_include_path = 0, $targetDir = false)
 {
     $type = 'csv';
     $uploads = wp_upload_dir();
     $targetDir = !$targetDir ? wp_all_import_secure_file($uploads['basedir'] . DIRECTORY_SEPARATOR . PMXI_Plugin::UPLOADS_DIRECTORY) : $targetDir;
     $tmpname = wp_unique_filename($targetDir, strlen(basename($filename)) < 30 ? basename($filename) : time());
     $localPath = $targetDir . '/' . urldecode(sanitize_file_name($tmpname));
     $fp = @fopen($localPath, 'w');
     $file = @gzopen($filename, 'rb', $use_include_path);
     if ($file) {
         $first_chunk = true;
         while (!gzeof($file)) {
             $chunk = gzread($file, 1024);
             if ($first_chunk and strpos($chunk, "<?") !== false and strpos($chunk, "</") !== false) {
                 $type = 'xml';
                 $first_chunk = false;
             }
             // if it's a 1st chunk, then chunk <? symbols to detect XML file
             @fwrite($fp, $chunk);
         }
         gzclose($file);
     } else {
         $tmpname = wp_unique_filename($targetDir, strlen(basename($filename)) < 30 ? basename($filename) : time());
         $localGZpath = $targetDir . '/' . urldecode(sanitize_file_name($tmpname));
         $request = get_file_curl($filename, $localGZpath, false, true);
         if (!is_wp_error($request)) {
             $file = @gzopen($localGZpath, 'rb', $use_include_path);
             if ($file) {
                 $first_chunk = true;
                 while (!gzeof($file)) {
                     $chunk = gzread($file, 1024);
                     if ($first_chunk and strpos($chunk, "<?") !== false and strpos($chunk, "</") !== false) {
                         $type = 'xml';
                         $first_chunk = false;
                     }
                     // if it's a 1st chunk, then chunk <? symbols to detect XML file
                     @fwrite($fp, $chunk);
                 }
                 gzclose($file);
             }
             @unlink($localGZpath);
         } else {
             return $request;
         }
     }
     @fclose($fp);
     if (preg_match('%\\W(gz)$%i', basename($localPath))) {
         if (@rename($localPath, str_replace('.gz', '.' . $type, $localPath))) {
             $localPath = str_replace('.gz', '.' . $type, $localPath);
         }
     } else {
         if (@rename($localPath, $localPath . '.' . $type)) {
             $localPath = $localPath . '.' . $type;
         }
     }
     return array('type' => $type, 'localPath' => $localPath);
 }
Example #12
0
 function read()
 {
     if ($this->stream instanceof \IO\Buffer\Stream) {
         $length = $this->stream->getLength();
     } else {
         $length = $this->stream->getFile()->getSize(true);
     }
     return gzread($this->stream->getPointer(), $length);
 }
Example #13
0
function main()
{
    $fnam = tempnam('/tmp', 'unittest');
    $f = fopen('compress.zlib://file://' . $fnam, 'w');
    fwrite($f, 'hello, world');
    fclose($f);
    $f = gzopen($fnam, 'r');
    var_dump(gzread($f, 1024));
    gzclose($f);
}
Example #14
0
 public function read($file)
 {
     $open = gzopen($file, 'r');
     if (empty($open)) {
         throw new FileNotFoundException('Error', 'fileNotFound', $file);
     }
     $return = gzread($open, 8096);
     gzclose($open);
     return $return;
 }
 /**
  * @param $fileName
  * @param $outputFilePath
  */
 private function decompressFile($fileName, $outputFilePath)
 {
     $gz = gzopen($fileName, 'rb');
     $outputFile = fopen($outputFilePath, 'wb');
     while (!gzeof($gz)) {
         fwrite($outputFile, gzread($gz, 4096));
     }
     fclose($outputFile);
     gzclose($gz);
 }
function uncompress($srcName, $dstName)
{
    $sfp = gzopen($srcName, "rb");
    $fp = fopen($dstName, "w");
    while ($string = gzread($sfp, 4096)) {
        fwrite($fp, $string, strlen($string));
    }
    gzclose($sfp);
    fclose($fp);
}
Example #17
0
 private function extractUsingExt($file, $targetFilepath)
 {
     $archiveFile = gzopen($file, 'rb');
     $targetFile = fopen($targetFilepath, 'wb');
     while ($string = gzread($archiveFile, 4096)) {
         fwrite($targetFile, $string, Platform::strlen($string));
     }
     gzclose($archiveFile);
     fclose($targetFile);
 }
Example #18
0
function gunzip($file)
{
    $file = @gzopen($file, 'rb', 0);
    if ($file) {
        $data = '';
        while (!gzeof($file)) {
            $data .= gzread($file, 1024);
        }
        gzclose($file);
    }
    return $data;
}
Example #19
0
 /**
  * Download remote data store
  *
  * Used by the mautic:iplookup:update_data command and form fetch button (if applicable) to update local IP data stores
  *
  * @return bool
  */
 public function downloadRemoteDataStore()
 {
     $connector = HttpFactory::getHttp();
     $package = $this->getRemoteDateStoreDownloadUrl();
     try {
         $data = $connector->get($package);
     } catch (\Exception $exception) {
         $this->logger->error('Failed to fetch remote IP data: ' . $exception->getMessage());
     }
     $tempTarget = $this->cacheDir . '/' . basename($package);
     $tempExt = strtolower(pathinfo($package, PATHINFO_EXTENSION));
     $localTarget = $this->getLocalDataStoreFilepath();
     $localTargetExt = strtolower(pathinfo($localTarget, PATHINFO_EXTENSION));
     try {
         $success = false;
         switch (true) {
             case $localTargetExt === $tempExt:
                 $success = (bool) file_put_contents($localTarget, $data->body);
                 break;
             case 'gz' == $tempExt:
                 if (function_exists('gzdecode')) {
                     $success = (bool) file_put_contents($localTarget, gzdecode($data->body));
                 } elseif (function_exists('gzopen')) {
                     if (file_put_contents($tempTarget, $data->body)) {
                         $bufferSize = 4096;
                         // read 4kb at a time
                         $file = gzopen($tempTarget, 'rb');
                         $outFile = fopen($localTarget, 'wb');
                         while (!gzeof($file)) {
                             fwrite($outFile, gzread($file, $bufferSize));
                         }
                         fclose($outFile);
                         gzclose($file);
                         @unlink($tempTarget);
                         $success = true;
                     }
                 }
                 break;
             case 'zip' == $tempExt:
                 file_put_contents($tempTarget, $data->body);
                 $zipper = new \ZipArchive();
                 $zipper->open($tempTarget);
                 $success = $zipper->extractTo($localTarget);
                 $zipper->close();
                 @unlink($tempTarget);
                 break;
         }
     } catch (\Exception $exception) {
         error_log($exception);
         $success = false;
     }
     return $success;
 }
Example #20
0
 function gunzip($infile, $outfile)
 {
     $string = null;
     $zp = gzopen($infile, "r");
     while (!gzeof($zp)) {
         $string .= gzread($zp, 4096);
     }
     gzclose($zp);
     $fp = fopen($outfile, "w");
     fwrite($fp, $string, strlen($string));
     fclose($fp);
 }
Example #21
0
 public function start()
 {
     if ($this->ttl != -1 && file_exists($this->fragment) && strtotime($this->ttl, filemtime($this->fragment)) >= time()) {
         $fp = gzopen($this->fragment, 'r');
         while (!feof($fp)) {
             echo gzread($fp, 1024);
         }
         gzclose($fp);
         return false;
     }
     ob_start();
     return true;
 }
Example #22
0
 /**
  * vrati element ikdyz je xml v zipu
  * @param string $url
  * @return \SimpleXMLElement
  */
 protected function _getSimpleXmlElement($url)
 {
     $header = get_headers($url, 1);
     if (isset($header['Content-Type']) and $header['Content-Type'] == 'application/gzip') {
         $gz = gzopen($url, 'r');
         $xml = '';
         while ($res = gzread($gz, 2048)) {
             $xml .= $res;
         }
         return simplexml_load_string($xml);
     }
     return simplexml_load_file($url);
 }
Example #23
0
 /**
  * Extracts single gzipped file. If archive will contain more then one file you will got a mess.
  *
  * @param $archive
  * @param $destination
  * @return int
  */
 public function unGZip($archive, $destination)
 {
     $buffer_size = 4096;
     // read 4kb at a time
     $archive = gzopen($archive, 'rb');
     $dat = fopen($destination, 'wb');
     while (!gzeof($archive)) {
         fwrite($dat, gzread($archive, $buffer_size));
     }
     fclose($dat);
     gzclose($archive);
     return filesize($destination);
 }
Example #24
0
 static function install($source, $filename)
 {
     $target = SIMPLE_EXT . substr($filename, 0, -3);
     setup::out("{t}Download{/t}: " . $source . " ...");
     if ($fz = gzopen($source, "r") and $fp = fopen($target, "w")) {
         $i = 0;
         while (!gzeof($fz)) {
             $i++;
             setup::out(".", false);
             if ($i % 160 == 0) {
                 setup::out();
             }
             fwrite($fp, gzread($fz, 16384));
         }
         gzclose($fz);
         fclose($fp);
     } else {
         sys_die("{t}Error{/t}: gzopen [2] " . $source);
     }
     setup::out();
     if (!file_exists($target) or filesize($target) == 0 or filesize($target) % 10240 != 0) {
         sys_die("{t}Error{/t}: file-check [3] Filesize: " . filesize($target) . " " . $target);
     }
     setup::out(sprintf("{t}Processing %s ...{/t}", basename($target)));
     $tar_object = new Archive_Tar($target);
     $tar_object->setErrorHandling(PEAR_ERROR_PRINT);
     $tar_object->extract(SIMPLE_EXT);
     $file_list = $tar_object->ListContent();
     if (!is_array($file_list) or !isset($file_list[0]["filename"]) or !is_dir(SIMPLE_EXT . $file_list[0]["filename"])) {
         sys_die("{t}Error{/t}: tar [4] " . $target);
     }
     self::update_modules_list();
     $ext_folder = db_select_value("simple_sys_tree", "id", "anchor=@anchor@", array("anchor" => "extensions"));
     foreach ($file_list as $file) {
         sys_chmod(SIMPLE_EXT . $file["filename"]);
         setup::out(sprintf("{t}Processing %s ...{/t}", SIMPLE_EXT . $file["filename"]));
         if (basename($file["filename"]) == "install.php") {
             setup::out("");
             require SIMPLE_EXT . $file["filename"];
             setup::out("");
         }
         if (basename($file["filename"]) == "readme.txt") {
             $data = file_get_contents(SIMPLE_EXT . $file["filename"]);
             setup::out(nl2br("\n" . q($data) . "\n"));
         }
         if (!empty($ext_folder) and basename($file["filename"]) == "folders.xml") {
             setup::out(sprintf("{t}Processing %s ...{/t}", "folder structure"));
             folders::create_default_folders(SIMPLE_EXT . $file["filename"], $ext_folder, false);
         }
     }
 }
Example #25
0
function ewiki_spage($id, &$data, $action)
{
    global $ewiki_spages, $ewiki_plugins, $ewiki_t;
    $r = "";
    #-- filename from $id
    $fn = $ewiki_spages[strtolower($id)];
    #-- php file
    if (strpos($fn, ".php") || strpos($fn, ".htm")) {
        #-- start new ob level
        ob_start();
        ob_implicit_flush(0);
        #-- prepare environment
        global $ewiki_id, $ewiki_title, $ewiki_author, $ewiki_ring, $ewiki_t, $ewiki_config, $ewiki_action, $_EWIKI, $ewiki_auth_user, $ewiki_headers, $headers;
        $ewiki_headers = array();
        $headers =& $ewiki_headers;
        #-- execute script
        include $fn;
        #-- close ob
        $r = ob_get_contents();
        ob_end_clean();
        #-- add headers
        if ($ewiki_headers) {
            headers(implode("\n", $ewiki_headers));
        }
        $clean_html = true;
    } elseif (EWIKI_SPAGES_BIN && !headers_sent() && preg_match('#\\.(png|gif|jpe?g|zip|tar)#', $fn)) {
        $ct = "application/octet-stream";
        if (function_exists("mime_content_type")) {
            $ct = mime_content_type($fn);
        }
        header("Content-Type: {$ct}");
        header("ETag: ewiki:spages:" . md5($r) . ":0");
        header("Last-Modified: " . gmstrftime($ewiki_t["C"]["DATE"], filemtime($fn)));
        passthru($r);
    } else {
        $f = gzopen($fn, "rb");
        $r = gzread($f, 256 << 10);
        gzclose($f);
        #-- render as text/plain, text/x-wiki
        if ($r) {
            $r = $ewiki_plugins["render"][0]($r);
        }
    }
    #-- strip <html> and <head> parts (if any)
    if ($clean_html) {
        $r = preg_replace('#^.+<body[^>]*>(.+)</body>.+$#is', '$1', $r);
    }
    #-- return body (means successfully handled)
    return $r;
}
 /**
  * @param $filename
  * @return string
  */
 protected function decompressFile($filename)
 {
     $dataDir = $this->getDataDirectoryPath();
     $zip = gzopen($filename, 'rb');
     $outputUncompressedTempFileName = tempnam($dataDir, 'dbupdate');
     $outputUncompressedTempFile = fopen($outputUncompressedTempFileName, 'wb');
     $bufferSize = 4096;
     while (!gzeof($zip)) {
         fwrite($outputUncompressedTempFile, gzread($zip, $bufferSize));
     }
     fclose($outputUncompressedTempFile);
     gzclose($zip);
     return $outputUncompressedTempFileName;
 }
Example #27
0
 /**
  * Executes the ImportSqlDump Task.
  *
  * @return Robo\Result
  */
 public function run()
 {
     // Lets make sure we have a database
     if (!$this->taskCreateDb()->host($this->host)->user($this->user)->pass($this->pass)->name($this->name)->dropTables(true)->run()->wasSuccessful()) {
         throw new RuntimeException('We failed to create the db.');
     }
     // Do we need to uncompress it first?
     if (strpos($this->dump, '.gz') !== false) {
         // Create a temp dump file
         $temp_dump = tempnam(sys_get_temp_dir(), 'dump');
         // Decompress the dump file
         if ($fp_out = fopen($temp_dump, 'wb')) {
             if ($fp_in = gzopen($this->dump, 'rb')) {
                 while (!gzeof($fp_in)) {
                     fwrite($fp_out, gzread($fp_in, 1024 * 512));
                 }
                 fclose($fp_in);
             } else {
                 throw new RuntimeException('Failed to open source dump file for reading.');
             }
             gzclose($fp_out);
         } else {
             throw new RuntimeException('Failed to open temp dump file for writing.');
         }
         // Set the dump the deflated version
         $this->dump = $temp_dump;
         // Delete the temp later
         $delete_me = $this->dump;
     }
     // Construct the command to import the dump
     $cmd = 'mysql -h' . $this->host . ' -u' . $this->user;
     if (!empty($this->pass)) {
         $cmd .= ' -p' . $this->pass;
     }
     $cmd .= ' ' . $this->name . ' < ' . $this->dump;
     // Run the command
     if (!$this->taskExec($cmd)->run()->wasSuccessful()) {
         throw new RuntimeException('We failed to import your dump. ' . 'HINT: Is the `mysql` binary in your "PATH"?');
     }
     // Delete the deflated temp dump file
     if (isset($delete_me)) {
         $this->printTaskInfo('Deleting temp dump file.');
         if (!unlink($delete_me)) {
             return Result::error($this, 'Couldn`t delete temp file.');
         }
     }
     // If we get to here assume everything worked
     return Result::success($this);
 }
Example #28
0
 /**
  * Decompress a file with gzip
  *
  * @param  string $file
  * @return mixed
  */
 public static function decompress($file)
 {
     $gz = gzopen($file, 'r');
     $uncompressed = '';
     // Read the uncompressed data
     while (!feof($gz)) {
         $uncompressed .= gzread($gz, 4096);
     }
     // Close the Gzip compressed file and write
     // the data to the uncompressed file
     gzclose($gz);
     $newFile = stripos($file, '.tgz') !== false ? str_replace('.tgz', '.tar', $file) : str_replace('.gz', '', $file);
     file_put_contents($newFile, $uncompressed);
     return $newFile;
 }
 public function testWriteStream()
 {
     $dest = __DIR__ . '/writeTest.gz';
     $fh = fopen($dest, 'w');
     $a = Psr7\stream_for($fh);
     $gzStream = new GzStreamGuzzle($a);
     $content = 'The quick brown fox jumps over the lazy dog';
     $gzStream->write($content);
     $gzStream->close();
     // test with zlib
     $fh = gzopen($dest, 'r');
     $buffer = gzread($fh, 4096);
     $this->assertEquals($content, $buffer);
     gzclose($fh);
 }
Example #30
0
 function extractGzip($src, $dest = false)
 {
     $zp = gzopen($src, "r");
     $data = '';
     while (!gzeof($zp)) {
         $data .= gzread($zp, 1024 * 1024);
     }
     gzclose($zp);
     if (empty($dest)) {
         return $data;
     } elseif (file_put_contents($dest, $data)) {
         return $dest;
     }
     return false;
 }