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: Sun, 25 Nov 2007

view this page in

Bzip2 압축 함수

소개

bzip2 함수는 손쉽게 bzip2 (.bz2) 압축 파일을 읽고 쓸수 있도록 해준다.

요구 조건

이 모듈은 Julian Seward 의 » bzip2 라이브러리 함수를 사용한다. 이 모듈은 bzip2/libbzip2 버전 >= 1.0.x 을 요구한다..

설치

Bzip2 는 PHP 에서 기본적으로 활성화되지 않는다. bzip2 지원을 활성화시키고 PHP 를 컴파일하기 위해서는 --with-bz2[=DIR] 설정 옵션을 사용해야 한다.

실행시 설정

이 확장은 php.ini 설정이 존재하지 않습니다.

자원형

이 확장은 한가지 리소스 타입을 정의한다: 작동중인 bz2 파일 식별 파일 포인터

예약 상수

이 확장은 상수를 정의하지 않습니다.

예제

다음 예제코드는 임의의 파일을 열고 그 파일에 테스트 문자열을 쓰고나서, 그 파일의 내용을 출력한다.

Example#1 간단한 bzip2 예제코드

<?php

$filename 
"/tmp/testfile.bz2";
$str "This is a test string.\n";

// 쓰기전용으로 파일을 연다
$bz bzopen($filename"w");

// 파일에 문자열을 쓴다
bzwrite($bz$str);

// 파일을 닫는다
bzclose($bz);

// 읽기전용으로 파일을 연다
$bz bzopen($filename"r");

// 10 문자를 읽는다
print bzread($bz10);

// 파일의 끝까지 출력( 또는 다음 1024 문자) 하고 나서 파일을 닫는다.
print bzread($bz);

bzclose($bz);

?>

Table of Contents

  • bzclose — bzip2 파일 포인터를 닫는다
  • bzcompress — 문자열을 bzip2 인코딩 데이터로 압축한다
  • bzdecompress — bzip2 인코딩 데이터의 압축을 해제한다
  • bzerrno — bzip2 에러 번호를 반환한다
  • bzerror — bzip2 에러 번호와 에러 문자열을 배열로 반환한다
  • bzerrstr — bzip2 에러 문자열을 반환한다
  • bzflush — 버퍼에 담긴 모든 데이터를 강제로 기록한다
  • bzopen — bzip2 압축 파일을 연다
  • bzread — bzip2 파일을 바이너리 형태로 판독
  • bzwrite — bzip2 파일을 바이너리 형태로 기록


add a note add a note User Contributed Notes
Bzip2
ec10 at gmx dot net
20-May-2004 11: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: Sun, 25 Nov 2007
 
 
show source | credits | stats | sitemap | contact | advertising | mirror sites