0
파일을 쓰는 동안 지정된 크기를 초과하는지 확인해야합니다. 내가 지정한 크기에 도달하면 필기를 중지하고 예외를 throw해야합니다. 정상 파일글 쓰는 동안 Gzip 및 Bzip2 파일의 오버플로를 어떻게 감지 할 수 있습니까?
예 :
는$handle = fopen($filename, 'wb');
while (true) {
// its work
if (fstat($handle)['size'] + strlen($string) > BYTE_LIMIT) {
throw SizeOverflowException::withLimit(BYTE_LIMIT);
}
fwrite($this->handle, $string);
}
fclose($handle);
아니면 독립적
$handle = fopen($filename, 'wb');
$used_bytes = 0;
while (true) {
if ($used_bytes + strlen($string) > BYTE_LIMIT) {
throw SizeOverflowException::withLimit(BYTE_LIMIT);
}
fwrite($this->handle, $string);
$used_bytes += strlen($string);
}
fclose($handle);
예 물품의 gzip 사용 된 바이트 수를 카운트 할 수 Bzip2의 비슷하게
$handle = gzopen($filename, 'wb9');
while (true) {
// not work
// fstat($handle) === false
//if (fstat($handle)['size'] + strlen($string) > BYTE_LIMIT) {
// throw SizeOverflowException::withLimit(BYTE_LIMIT);
//}
gzwrite($this->handle, $string);
}
gzclose($handle);
:
$handle = bzopen($filename, 'w');
while (true) {
// not work
// fstat($handle) === false
//if (fstat($handle)['size'] + strlen($string) > BYTE_LIMIT) {
// throw SizeOverflowException::withLimit(BYTE_LIMIT);
//}
bzwrite($this->handle, $string);
}
bzclose($handle);
이 경우 fstat()
이 작동하지 않는 이유를 이해하지만 어떻게이 문제를 해결할 수 있습니까?
이제 비 압축 모드에서 사용되는 바이트 수만 계산할 수 있습니다.
** 좋은 아이디어. 고마워. ** 불행히도, 나는 PHP 5.6을 지원해야하고 여전히 Bzip2 (( – ghost404