CXI. Zlib Compression Functions

이 모듈은 Jean-loup Gailly 과 Mark Adler 의 zlib 사용하며 gzip(.gz)로 압축된 파일을 잘 읽고 쓸수 있다. 이 모듈은 zlib 1.0.9버젼 이상과 사용할 수 있다.

이 모듈은 gzip 압축된 파일과 연동하는 대부분의 filesystem 함수 버젼을 포함하고 있다. (and uncompressed files, too, but not with sockets).

참고: 현재 CVS 4.0.4-dev 버젼은 .gz-files를 위한 fopen-wrapper를 소개하고 있다. 압축된 파일을 다루는 특별한 'zlib:'URL을 사용할 수 있기 위하여 일반적인 f*() 파일 제어 함수가 사용되며 fopen()함수 호출 전에 이미 알고 있는 파일명이나 경로가 'zlib:'와 함께 선행되어야 한다.

이 경우 fopencookie() 함수를 제공하는 C 런타임 라이브러리가 필요하다. 현재 이것을 제공하는 라이브러리는 GNU libc가 유일하다.

Small code example

임시 파일을 열어 테스트 문자를 기록하고, 그 내용을 두번 출력한다 .

예 1. Small Zlib Example

<?php

$filename = tempnam ('/tmp', 'zlibtest').'.gz';
print "<html>\n<head></head>\n<body>\n<pre>\n";
$s = "Only a test, test, test, test, test, test, test, test!\n";

// open file for writing with maximum compression
$zp = gzopen($filename, "w9");

// write string to file
gzwrite($zp, $s);

// close file
gzclose($zp);

// open file for reading
$zp = gzopen($filename, "r");

// read 3 char
print gzread($zp, 3);

// output until end of the file and close it.
gzpassthru($zp);

print "\n";

// open file and print content (the 2nd time).
if (readgzfile($filename) != strlen($s)) {
        echo "Error with zlib functions!";
}
unlink($filename);
print "</pre>\n</h1></body>\n</html>\n";

?>
차례
gzclose -- 지정된 .gz 파일을 닫는다.
gzcompress -- .gz로 문자를 압축한다.
gzdeflate -- Deflate a string
gzencode -- Create a gzip compressed string
gzeof -- 지정된 .gz 파일의 끝을 테스트한다.
gzfile -- gz 파일 내용을 배열로 읽어들인다.
gzgetc -- 지정된 .gz파일로부터 문자를 추출한다.
gzgets -- 지정된 파일로 부터 라인을 읽어 들인다.
gzgetss --  .gz 파일로부터 HTML 태그를 제외하고 한 라인을 읽는다,
gzinflate -- Inflate a deflated string
gzopen -- .gz파일을 연다
gzpassthru --  지정된 파일의 남아있는 모든 데이타를 출력한다.
gzputs -- 지정된 .gz 파일에 기록한다.
gzread -- .gz로부터 바이트값을 읽어들인다
gzrewind -- 지정된 .gz파일을 리와인드한다
gzseek -- 지정된 .gz 파일을 검색한다.
gztell -- 지정된 .gz 파일의 read/write position을 리턴한다
gzuncompress -- gz로 압축된 문자를 압축해제 한다.
gzwrite -- 지정된 string을 .gz파일 스트림에 기록한다.
readgzfile -- .gz파일을 출력한다