PHP  
downloads | documentation | faq | getting help | mailing lists | reporting bugs | php.net sites | links | my php.net 
search for in the  
<bcsubbzclose>
view the version of this page
Last updated: Sun, 02 May 2004

V. Funzioni di compressione Bzip2

Introduzione

Le funzioni bzip2 sono utilizzate per leggere e scrivere in modo trasparente i file compressi con bzip2 (.bz2).

Requisiti

Questo modulo tuilizza le funzioni della libreria bzip2 di Julian Seward. Questo modulo richiede che la versione di bzip2/libbzip2 sia >= 1.0.x.

Installazione

Il supporto di bzip2 in PHP non è abilitato di default. Si deve utilizzare l'opzione --with-bz2[=DIR] quando si compila PHP, per abilitare il supporto bzip2.

Configurazione di Runtime

Questa estensione non definisce alcuna direttiva di configurazione in php.ini

Tipi di risorse

Questa estensione definisce un tipo di risorsa: un puntatore a file che identifica il file bz2 su cui lavorare.

Costanti predefinite

Questa estensione non definisce alcuna costante.

Esempi

Questo esempio apre un file temporaneo e scrive una stringa di prova su di esso, quindi stampa il contenuto del file.

Esempio 1. breve esempio di bzip2

<?php

$nomefile
= "/tmp/filediprova.bz2";
$str = "Questa è una stringa di prova.\n";

// apre il file in lettura
$bz = bzopen($nomefile, "w");

// scrive la stringa sul file
bzwrite($bz, $str);

// chiude il file
bzclose($bz);

// apre il file in lettura
$bz = bzopen($nomefile, "r");

// legge 10 caratteri
echo bzread($bz, 10);

// stampa fino alla fine del file (o fino ai prossimi 1024 caratteri) e chiude il file.
echo bzread($bz);

bzclose($bz);

?>
Sommario
bzclose -- Chiude un puntatore a un file bzip2
bzcompress -- Comprime una stringa nel formato bzip2
bzdecompress -- Decomprime dati codificati con bzip2
bzerrno -- Restituisce il codice d'errore bzip2
bzerror -- Restituisce il codice d'errore bzip2 e la stringa corrispondente in un array
bzerrstr -- restituisce la stringa di errore bzip2
bzflush -- Forza la scrittura di tutti i dati nel buffer
bzopen -- Apre un file compresso bzip2
bzread -- Esegue la lettura binaria di un file bzip2
bzwrite -- Esegue la scrittura binaria di un file bzip2


add a note add a note User Contributed Notes
Funzioni di compressione Bzip2
ec10 at gmx dot net
20-May-2004 05:34
/**
 * @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;
}

<bcsubbzclose>
 Last updated: Sun, 02 May 2004
show source | credits | sitemap | contact | advertising | mirror sites 
Copyright © 2001-2004 The PHP Group
All rights reserved.
This mirror generously provided by: Italia OnLine S.p.a.
Last updated: Fri May 21 04:11:23 2004 CEST