Ftell在对文件指针应用流过滤器时报告意外值

时间:2013-11-22 13:26:26

标签: php deflate ftell

我正在尝试在应用ftell流过滤器时使用zlib.deflate计算写入文件的数据。但基于ftell的大小与写入文件的实际数据大小不同。

以下是我的代码     

$handler_read = fopen('image.jpg', 'rb');
$handler_write = fopen('image.jpg.z', 'wb');

$stream_filter = stream_filter_append($handler_write, 'zlib.deflate', STREAM_FILTER_WRITE);

printf("Cursor at: %s%s", ftell($handler_write), PHP_EOL);

$start = ftell($handler_write);
while(!feof($handler_read)) {

    $chunk = fread($handler_read, 1024*512);

    fwrite($handler_write, $chunk);

    printf("Cursor at: %s%s", ftell($handler_write), PHP_EOL);

}
$end = ftell($handler_write);

fclose($handler_read);
fclose($handler_write);

printf("Actual size: %s%s", filesize('image.jpg.z'), PHP_EOL );
printf("Curser based size: %s%s", $end - $start, PHP_EOL);

以下是结果

Cursor at: 0
Cursor at: 463944
Cursor at: 989108
Cursor at: 1055270
Actual size: 1148880
Curser based size: 1055270

0 个答案:

没有答案