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가 유일하다.
임시 파일을 열어 테스트 문자를 기록하고, 그 내용을 두번 출력한다 .
예 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";
?> |
|