PHP
downloads | documentation | faq | getting help | mailing lists | reporting bugs | php.net sites | links | conferences | my php.net

search for in the

bzclose> <bcompiler_write_included_filename
Last updated: Sat, 24 Mar 2007

view this page in

IX. Kompresní funkce bzip2

Úvod

Funkce bzip2 se používají k transparentnímu čtení a zápisu souborů komprimovaných algoritmem bzip2 (.bz2).

Požadavky

Tento modul používá funkce z knihovny » bzip2 od Juliana Sewarda. Tento modul vyžaduje bzip2/libbzip2 verze >= 1.0.x.

Instalace

Podpora bzip2 není v PHP implicitnì k dispozici. K aktivaci budete muset pøi kompilaci PHP pou¾ít konfiguraèní volbu --with-bz2[=DIR].

Konfigurace běhu

Toto rozšíření nemá definováno žádné konfigurační direktivy.

Typy prostředků

Toto rozšíření definuje jeden typ prostředku: souborový ukazatel identifikující soubor bz2, nad kterým se pracuje.

Předdefinované konstanty

Toto rozšíření nemá definovány žádné konstanty.

Příklady

Tento příklad otevře dočasný soubor a zapíše do něj testovací řetezec; potom vypíše obsah souboru.

Příklad 264. Malý příklad na bzip2

<?php

$filename
= "/tmp/testfile.bz2";
$str = "Toto je testovací řetězec.\n";

// otevři soubor pro zápis
$bz = bzopen($filename, "w");

// zapoš řetězec do souboru
bzwrite($bz, $str);

// zavři soubor
bzclose($bz);

// otevři soubor pro čtení
$bz = bzopen($filename, "r");

// přečti 10 znaků
print bzread($bz, 10);

// tiskni dokud není konec souboru (nebo následující 1024. znak) a zavři soubor 
print bzread($bz);

bzclose($bz);

?>

Obsah

bzclose — Zavře ukazatel na soubor bzip2
bzcompress — Zkomprimuje řetězec algoritmem bzip2
bzdecompress — Dekomprimuje data komprimovaná pomocí bzip2
bzerrno — Vrací číslo chyby bzip2
bzerror — Vrací v poli číslo a popis chyby bzip2
bzerrstr — Vrací popis chyby bzip2
bzflush — Vynutí zápis všech bufferovaných dat
bzopen — Otevře soubor komprimovaný pomocí bzip2
bzread — Binárně bezpečné čtení ze souboru bzip2
bzwrite — Binárně bezpečný zápis do souboru bzip2


add a note add a note User Contributed Notes
Kompresní funkce bzip2
ec10 at gmx dot net
20-May-2004 02:34
<?php
/**
 * @return bool
 * @param string $in
 * @param string $out
 * @desc compressing the file with the bzip2-extension
*/
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, "rb");
   
$out_file = bzopen ($out, "wb");
   
    while (!
feof ($in_file)) {
       
$buffer = fgets ($in_file, 4096);
        
bzwrite ($out_file, $buffer, 4096);
    }

   
fclose ($in_file);
   
bzclose ($out_file);
   
    return
true;
}

/**
 * @return bool
 * @param string $in
 * @param string $out
 * @desc uncompressing the file with the bzip2-extension
*/
function bunzip2 ($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 = bzopen ($in, "rb");
   
$out_file = fopen ($out, "wb");

    while (
$buffer = bzread ($in_file, 4096)) {
       
fwrite ($out_file, $buffer, 4096);
    }
 
   
bzclose ($in_file);
   
fclose ($out_file);
   
    return
true;
}
?>

bzclose> <bcompiler_write_included_filename
Last updated: Sat, 24 Mar 2007
 
 
show source | credits | sitemap | contact | advertising | mirror sites