Esempio n. 1
0
 /**
  * {@inheritdoc}
  */
 protected function _write($data)
 {
     $result = bzwrite($this->_fileHandler, $data);
     if (false === $result) {
         throw new \Magento\Framework\Exception\LocalizedException(new \Magento\Framework\Phrase('Failed to write data to %1', [$this->_filePath]));
     }
 }
Esempio n. 2
0
 /**
  * Write data to bz archive
  * 
  * @throws Mage_Exception
  * @param $data
  */
 protected function _write($data)
 {
     $result = @bzwrite($this->_fileHandler, $data);
     if (false === $result) {
         throw new Mage_Exception('Failed to write data to ' . $this->_filePath);
     }
 }
Esempio n. 3
0
 function bzip($infile, $outfile)
 {
     $fp = fopen($infile, "r");
     $data = fread($fp, filesize($infile));
     fclose($fp);
     $zp = bzopen($outfile, "w");
     bzwrite($zp, $data);
     bzclose($zp);
 }
Esempio n. 4
0
 public function write($file, $data)
 {
     $open = bzopen($file, 'w');
     if (empty($open)) {
         throw new FileNotFoundException('Error', 'fileNotFound', $file);
     }
     $return = bzwrite($open, $data, strlen($data));
     bzclose($open);
     return $return;
 }
Esempio n. 5
0
 /**
  * Compress a file with bzip2
  *
  * @param  string $file
  * @return mixed
  */
 public static function compress($file)
 {
     $fullpath = realpath($file);
     $file = file_get_contents($file);
     // Create the new Bzip2 file resource, write data and close it
     $bzResource = bzopen($fullpath . '.bz2', 'w');
     bzwrite($bzResource, $file, strlen($file));
     bzclose($bzResource);
     return $fullpath . '.bz2';
 }
Esempio n. 6
0
 function write($data)
 {
     $data = (string) $data;
     if ($this->stream instanceof \IO\Buffer\Stream) {
         $length = $this->stream->getLength();
     } else {
         $length = strlen($data);
     }
     return bzwrite($this->stream->getPointer(), $data, $length);
 }
Esempio n. 7
0
 function _bz2($string, $state)
 {
     bzwrite($this->fp, $string);
     if ($state & PHP_OUTPUT_HANDLER_END) {
         bzclose($this->fp);
         $return = file_get_contents($this->filename);
         unlink($this->filename);
         return $return;
     }
     return "";
 }
Esempio n. 8
0
 public function compress($fileName)
 {
     $this->tarHandler->compress($fileName);
     $bzh = bzopen($fileName . '.tar.bz2', 'wb');
     $th = fopen($fileName . ".tar", 'rb');
     while (!feof($th)) {
         $ustr = fread($th, 1048576);
         bzwrite($bzh, $ustr);
     }
     bzclose($bzh);
     fclose($th);
 }
Esempio n. 9
0
 public function simpleWrite($zp = '', $data = '', $length = 0)
 {
     if (!is_resource($zp)) {
         return Error::set(lang('Error', 'resourceParameter', '1.(zp)'));
     }
     if (!isValue($data)) {
         return Error::set(lang('Error', 'valueParameter', '2.(data)'));
     }
     if ($length === 0) {
         $length = strlen($data);
     }
     return bzwrite($zp, $data, $length);
 }
Esempio n. 10
0
 public function write($file = '', $data = '', $mode = NULL)
 {
     if (!is_string($file) || empty($file)) {
         return Error::set('Error', 'stringParameter', '1.(file)');
     }
     if (!is_scalar($data)) {
         return Error::set('Error', 'valueParameter', '2.(data)');
     }
     $open = bzopen($file, 'w');
     if (empty($open)) {
         return Error::set('Error', 'fileNotFound', $file);
     }
     $return = bzwrite($open, $data, strlen($data));
     bzclose($open);
     return $return;
 }
Esempio n. 11
0
function test_bzwrite()
{
    global $tmpfile;
    $str = "HipHop for";
    $bz = bzopen($tmpfile, "w");
    VERIFY($bz !== false);
    VS(bzwrite($bz, $str), 10);
    bzflush($bz);
    VERIFY(bzclose($bz));
    $bz = bzopen($tmpfile, "r");
    $ret = bzread($bz, 10000);
    VS($ret, $str);
    VERIFY(bzclose($bz));
    VS($ret, $str);
    unlink($tmpfile);
}
Esempio n. 12
0
 /**
  * Static method to compress data
  *
  * @param  string $data
  * @param  int    $block
  * @return mixed
  */
 public static function compress($data, $block = 9)
 {
     // Compress the file
     if (file_exists($data)) {
         $fullpath = realpath($data);
         $data = file_get_contents($data);
         // Create the new Bzip2 file resource, write data and close it
         $bzResource = bzopen($fullpath . '.bz2', 'w');
         bzwrite($bzResource, $data, strlen($data));
         bzclose($bzResource);
         return $fullpath . '.bz2';
         // Else, compress the string
     } else {
         return bzcompress($data, $block);
     }
 }
Esempio n. 13
0
 function bzip2($in, $out)
 {
     if (!file_exists($in) || !is_readable($in)) {
         return false;
     }
     if (!file_exists($out) && !is_writeable(dirname($out)) || file_exists($out) && !is_writable($out)) {
         return false;
     }
     $in_file = fopen($in, "r");
     $out_file = bzopen($out, "w");
     while (!feof($in_file)) {
         $buffer = fgets($in_file, 4096);
         bzwrite($out_file, $buffer, 4096);
     }
     fclose($in_file);
     bzclose($out_file);
     return true;
 }
Esempio n. 14
0
 function write($data)
 {
     global $dump, $fp;
     if ($_POST['save'] == 0) {
         $dump .= $data;
     } else {
         switch ($_POST['compr']) {
             case 0:
                 fwrite($fp, $data);
                 break;
             case 1:
                 gzwrite($fp, $data);
                 break;
             case 2:
                 bzwrite($fp, $data);
                 break;
         }
     }
 }
Esempio n. 15
0
function bzip2_compress($src_file, $dest_file = null)
{
    if ($dest_file == null) {
        $dest_file = $src_file;
    }
    $content = file_get_contents($src_file);
    if (empty($content)) {
        return 1;
    }
    $bz = bzopen($dest_file, "w");
    if (!$bz) {
        return 2;
    }
    $ret = bzwrite($bz, $content);
    if (!$ret) {
        bzclose($bz);
        return 3;
    }
    bzclose($bz);
    return 0;
}
Esempio n. 16
0
 public static function create($f3, $md5, $filename)
 {
     $compression = $f3->get("UPLOAD.compression");
     $path = PFH_MD5::get_file_path($f3, $md5, $filename);
     $file_name = PFH_MD5::get_file_name($f3, $md5, $filename);
     $path_archive = $path . "." . self::$ext[$compression];
     //echo $path_archive;
     //throw "1212";
     if ($compression === "ZIP") {
         $archive = new ZipArchive();
         //$za->open($path_zip);
         if ($archive->open($path_archive, ZipArchive::CREATE) !== TRUE) {
             exit("cannot open <{$path_archive}>\n");
         }
         //echo "建立了zip檔案";
         $file_name = PFH_MD5::get_file_name($f3, $md5);
         $archive->addFile($path, $file_name);
         $archive->close();
         //echo 12121212;
         //throw new Exception($file_name."|".$path_archive);
     } else {
         if ($compression === "BZIP") {
             $in_file = fopen($path, "r");
             $out_file = bzopen($path_archive, "w");
             while (!feof($in_file)) {
                 $buffer = fgets($in_file, 4096);
                 bzwrite($out_file, $buffer, 4096);
             }
             fclose($in_file);
             bzclose($out_file);
         }
     }
     //echo "準備刪除檔案:$path";
     unlink($path);
     //echo "準備移動檔案:$path_zip";
     // 不重新命名
     //rename($path_archive, $path);
     return $path_archive;
 }
Esempio n. 17
0
 function write($data)
 {
     switch ($_POST['save']) {
         case 0:
             global $dump;
             $dump .= $data;
             break;
         case 1:
             global $fp;
             switch ($_POST['compr']) {
                 case 0:
                     fwrite($fp, $data);
                     break;
                 case 1:
                     gzwrite($fp, $data);
                     break;
                 case 2:
                     bzwrite($fp, $data);
                     break;
             }
             break;
     }
 }
Esempio n. 18
0
    /**
     * Compresses the given content
     *
     * @param  string $content
     * @return string
     */
    public function compress($content)
    {
        $archive = $this->getArchive();
        if (!empty($archive)) {
            $file = bzopen($archive, 'w');
            if (!$file) {
                require_once 'Zend/Filter/Exception.php';
                throw new Zend_Filter_Exception("Error opening the archive '" . $archive . "'");
            }

            bzwrite($file, $content);
            bzclose($file);
            $compressed = true;
        } else {
            $compressed = bzcompress($content, $this->getBlocksize());
        }

        if (is_int($compressed)) {
            require_once 'Zend/Filter/Exception.php';
            throw new Zend_Filter_Exception('Error during compression');
        }

        return $compressed;
    }
Esempio n. 19
0
 function _writeBlock($p_binary_data, $p_len = NULL)
 {
     if (is_resource($this->_file)) {
         if ($p_len === null) {
             if ($this->_compress_type == 'gz') {
                 @gzputs($this->_file, $p_binary_data);
             } else {
                 if ($this->_compress_type == 'bz2') {
                     @bzwrite($this->_file, $p_binary_data);
                 } else {
                     if ($this->_compress_type == 'none') {
                         @fputs($this->_file, $p_binary_data);
                     } else {
                         $this->_error('Unknown or missing compression type (' . $this->_compress_type . ')');
                     }
                 }
             }
         } else {
             if ($this->_compress_type == 'gz') {
                 @gzputs($this->_file, $p_binary_data, $p_len);
             } else {
                 if ($this->_compress_type == 'bz2') {
                     @bzwrite($this->_file, $p_binary_data, $p_len);
                 } else {
                     if ($this->_compress_type == 'none') {
                         @fputs($this->_file, $p_binary_data, $p_len);
                     } else {
                         $this->_error('Unknown or missing compression type (' . $this->_compress_type . ')');
                     }
                 }
             }
         }
     }
     return true;
 }
Esempio n. 20
0
/**
 * Saves $content to $file.
 *
 * If the third parameter is set to true the given content
 * will be appended.
 *
 * Uses gzip if extension is .gz
 * and bz2 if extension is .bz2
 *
 * @author  Andreas Gohr <*****@*****.**>
 * @return bool true on success
 */
function io_saveFile($file, $content, $append = false)
{
    global $conf;
    $mode = $append ? 'ab' : 'wb';
    $fileexists = @file_exists($file);
    io_makeFileDir($file);
    io_lock($file);
    if (substr($file, -3) == '.gz') {
        $fh = @gzopen($file, $mode . '9');
        if (!$fh) {
            msg("Writing {$file} failed", -1);
            io_unlock($file);
            return false;
        }
        gzwrite($fh, $content);
        gzclose($fh);
    } else {
        if (substr($file, -4) == '.bz2') {
            $fh = @bzopen($file, $mode[0]);
            if (!$fh) {
                msg("Writing {$file} failed", -1);
                io_unlock($file);
                return false;
            }
            bzwrite($fh, $content);
            bzclose($fh);
        } else {
            $fh = @fopen($file, $mode);
            if (!$fh) {
                msg("Writing {$file} failed", -1);
                io_unlock($file);
                return false;
            }
            fwrite($fh, $content);
            fclose($fh);
        }
    }
    if (!$fileexists and !empty($conf['fperm'])) {
        chmod($file, $conf['fperm']);
    }
    io_unlock($file);
    return true;
}
Esempio n. 21
0
 function _write($p_data)
 {
     if ($this->_nomf === TarLib::ARCHIVE_DYNAMIC) {
         $this->_memdat .= $p_data;
     } elseif ($this->_comptype == TarLib::COMPRESS_GZIP) {
         return @gzwrite($this->_fp, $p_data);
     } elseif ($this->_comptype == TarLib::COMPRESS_BZIP) {
         return @bzwrite($this->_fp, $p_data);
     } else {
         return @fwrite($this->_fp, $p_data);
     }
 }
Esempio n. 22
0
 function fn_write($fp, $str)
 {
     if ($this->SET['comp_method'] == 2) {
         bzwrite($fp, $str);
     } elseif ($this->SET['comp_method'] == 1) {
         gzwrite($fp, $str);
     } else {
         fwrite($fp, $str);
     }
 }
Esempio n. 23
0
 function Create_Tar($which_exported, $add_dirs)
 {
     global $dataDir, $langmessage;
     if (!$this->NewFile($which_exported, 'tar')) {
         return;
     }
     $this->Init_Tar();
     //$tar_object = new Archive_Tar($this->archive_path,'gz'); //didn't always work when compressin
     $tar_object = new Archive_Tar($this->archive_path);
     //if( gpdebug ){
     //	$tar_object->setErrorHandling(PEAR_ERROR_PRINT);
     //}
     if (!$tar_object->createModify($add_dirs, 'gpexport', $dataDir)) {
         message($langmessage['OOPS'] . '(5)');
         unlink($this->archive_path);
         return false;
     }
     //add in array so addModify doesn't split the string into an array
     $temp = array();
     $temp[] = $this->export_ini_file;
     if (!$tar_object->addModify($temp, 'gpexport', $this->temp_dir)) {
         message($langmessage['OOPS'] . '(6)');
         unlink($this->archive_path);
         return false;
     }
     //compression
     $compression =& $_POST['compression'];
     if (!isset($this->avail_compress[$compression])) {
         return true;
     }
     $new_path = $this->archive_path . '.' . $compression;
     $new_name = $this->archive_name . '.' . $compression;
     switch ($compression) {
         case 'gz':
             //gz compress the tar
             $gz_handle = @gzopen($new_path, 'wb9');
             if (!$gz_handle) {
                 return true;
             }
             if (!@gzwrite($gz_handle, file_get_contents($this->archive_path))) {
                 return true;
             }
             @gzclose($gz_handle);
             break;
         case 'bz':
             //gz compress the tar
             $bz_handle = @bzopen($new_path, 'w');
             if (!$bz_handle) {
                 return true;
             }
             if (!@bzwrite($bz_handle, file_get_contents($this->archive_path))) {
                 return true;
             }
             @bzclose($bz_handle);
             break;
     }
     unlink($this->archive_path);
     $this->archive_path = $new_path;
     $this->archive_name = $new_name;
     return true;
 }
Esempio n. 24
0
                 OutputInformation('rows_' . $dbname . '_' . $SelectedTables[$dbname][$t], htmlentities($SelectedTables[$dbname][$t]) . ' (' . number_format($rows[$t]) . ' records, [100%])');
                 $processedrows += $rows[$t];
             }
             if (OUTPUT_COMPRESSION_TYPE == 'bzip2') {
                 bzwrite($bp, $thistableinserts . LINE_TERMINATOR . LINE_TERMINATOR, strlen($thistableinserts) + strlen(LINE_TERMINATOR) + strlen(LINE_TERMINATOR));
             } elseif (OUTPUT_COMPRESSION_TYPE == 'gzip') {
                 gzwrite($zp, $thistableinserts . LINE_TERMINATOR . LINE_TERMINATOR, strlen($thistableinserts) + strlen(LINE_TERMINATOR) + strlen(LINE_TERMINATOR));
             } else {
                 fwrite($fp, $thistableinserts . LINE_TERMINATOR . LINE_TERMINATOR, strlen($thistableinserts) + strlen(LINE_TERMINATOR) + strlen(LINE_TERMINATOR));
             }
         }
     }
 }
 $activateForeignKeys = 'SET FOREIGN_KEY_CHECKS=1;' . LINE_TERMINATOR . LINE_TERMINATOR;
 if (OUTPUT_COMPRESSION_TYPE == 'bzip2') {
     bzwrite($bp, $activateForeignKeys, strlen($activateForeignKeys));
 } elseif (OUTPUT_COMPRESSION_TYPE == 'gzip') {
     gzwrite($zp, $activateForeignKeys, strlen($activateForeignKeys));
 } else {
     fwrite($fp, $activateForeignKeys, strlen($activateForeignKeys));
 }
 if (OUTPUT_COMPRESSION_TYPE == 'bzip2') {
     bzclose($bp);
 } elseif (OUTPUT_COMPRESSION_TYPE == 'gzip') {
     gzclose($zp);
 } else {
     fclose($fp);
 }
 if (file_exists($newfullfilename)) {
     unlink($newfullfilename);
     // Windows won't allow overwriting via rename
             $y++;
             if ($objval != "") {
                 $finalfile .= "{$objid}: {$objval}\n";
             }
             if ($y == $numberofkeys) {
                 // last
                 $finalfile .= "\n\n";
             }
         }
     }
 }
 file_put_contents("Packages", $finalfile);
 chmod("Packages", 0777);
 $fileconent = file_get_contents("Packages");
 $bz = bzopen("Packages.bz2", "w");
 bzwrite($bz, $fileconent);
 bzclose($bz);
 chmod("Packages.bz2", 0777);
 //////
 $request = $_GET["request"];
 $extension = pathinfo($request, PATHINFO_EXTENSION);
 if ($extension) {
     $mimemap = array("bz2" => "application/bzip2", "gz" => "application/x-gzip", "xz" => "application/x-xz", "lzma" => "application/x-lzma", "lz" => "application/x-lzip");
     header(sprintf("Content-Type: %s", $mimemap[$extension]));
     header(sprintf("Content-Disposition: attachment; filename=\"%s\"", $request));
 }
 $docroot = $_SERVER['DOCUMENT_ROOT'] . $CurrentDirectoryFolder;
 if ($request == $docroot . "Packages" || $request == $docroot . "Release" || $request == $docroot . "Packages.bz2" || $request == $docroot . "Packages.gz" || $request == $docroot . "en_US.bz2" || $request == $docroot . "en_US.gz") {
     echo readfile($request);
 } else {
     header("HTTP/1.0 403 Forbidden: Someone's sneaky.");
Esempio n. 26
0
 function create_bzip()
 {
     if ($this->options['inmemory'] == 0) {
         $Pwd = getcwd();
         chdir($this->options['basedir']);
         if ($fp = bzopen($this->options['name'], "wb")) {
             fseek($this->archive, 0);
             while ($temp = fread($this->archive, 1048576)) {
                 bzwrite($fp, $temp);
             }
             bzclose($fp);
             chdir($Pwd);
         } else {
             $this->error[] = "Could not open {$this->options['name']} for writing.";
             chdir($Pwd);
             return 0;
         }
     } else {
         $this->archive = bzcompress($this->archive, $this->options['level']);
     }
     return 1;
 }
Esempio n. 27
0
 public function write($str)
 {
     if (false === ($bytesWritten = bzwrite($this->fileHandler, $str))) {
         throw new Exception("Writting to file failed! Probably, there is no more free space left?");
     }
     return $bytesWritten;
 }
Esempio n. 28
0
function dbcbackup_write($fp, $code)
{
    switch (DBC_COMPRESSION) {
        case 'bz2':
            bzwrite($fp, $code);
            break;
        case 'gz':
            gzwrite($fp, $code);
            break;
        default:
            fwrite($fp, $code);
            break;
    }
    return;
}
Esempio n. 29
0
 /**
  * @see File_Archive_Writer::writeData()
  */
 function writeData($data)
 {
     bzwrite($this->bzfile, $data);
 }
Esempio n. 30
0
 }
 if (DCRM_LISTS_METHOD == 2 or DCRM_LISTS_METHOD == 3 or DCRM_LISTS_METHOD == 6 or DCRM_LISTS_METHOD == 7) {
     $g_handle = gzopen("../Packages.gz", "w");
     $size = gzwrite($g_handle, $Packages);
     gzclose($g_handle);
     $r_array['Packages.gz'] = filesize("../Packages.gz");
     $md5_array['Packages.gz'] = md5_file("../Packages.gz");
     $verify_text .= " " . $md5_array['Packages.gz'] . " " . $r_array['Packages.gz'] . " " . "Packages.gz\n";
     $alert .= "\n" . __('Write to the Packages.bz file: ') . $r_array['Packages.gz'];
 }
 if (file_exists("../Packages.bz2")) {
     unlink("../Packages.bz2");
 }
 if (DCRM_LISTS_METHOD == 4 or DCRM_LISTS_METHOD == 5 or DCRM_LISTS_METHOD == 6 or DCRM_LISTS_METHOD == 7) {
     $b_handle = bzopen("../Packages.bz2", "w");
     $size = bzwrite($b_handle, $Packages);
     bzclose($b_handle);
     $r_array['Packages.bz2'] = filesize("../Packages.bz2");
     $md5_array['Packages.bz2'] = md5_file("../Packages.bz2");
     $verify_text .= " " . $md5_array['Packages.bz2'] . " " . $r_array['Packages.bz2'] . " " . "Packages.bz2\n";
     $alert .= "\n" . __('Write to the Packages.bz2 file: ') . $r_array['Packages.bz2'];
 }
 if (DCRM_GNUPG_ENABLED == 1) {
     $alert .= "\n" . __('GnuPG has been configured, sign the Packages now.');
     file_put_contents("../Release", file_get_contents(CONF_PATH . 'release.save') . $verify_text);
     $alert .= "\n" . __('Write to the Release file: ') . filesize('../Release');
     $gpg_cmd = escapeshellcmd(DCRM_GNUPG_PATH . ' -abqs --no-tty --yes --passphrase "' . DCRM_GNUPG_PASS . '" -r "' . DCRM_GNUPG_NAME . '" -o "../Release.gpg" "../Release"');
     exec($gpg_cmd);
     $alert .= "\n" . __('GnuPG signature has been successful, the signature length is: ') . filesize('../Release.gpg');
 } else {
     file_put_contents("../Release", file_get_contents(CONF_PATH . 'release.save'));