#16689 [Fbk->NoF]: bzread has no reliable way of detecting eof

From: Date: Fri, 30 Aug 2002 05:00:12 +0000
Subject: #16689 [Fbk->NoF]: bzread has no reliable way of detecting eof
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-18215@lists.php.net to get a copy of this message
ID: 16689 Updated by: php-bugs@lists.php.net Reported By: joshbuddy@hotmail.com -Status: Feedback +Status: No Feedback Bug Type: Bzip2 Related Operating System: win32 PHP Version: 4.1.2 New Comment: No feedback was provided for this bug for over a month, so it is being suspended automatically. If you are able to provide the information that was originally requested, please do so and change the status of the bug back to "Open". Previous Comments: ------------------------------------------------------------------------ [2002-04-20 05:55:28] wez@php.net Can you try a CVS snapshot? Try: http://php-bin-snaps.sourceforge.net/ I've double checked the code: in the CVS version, bzread will return a zero-length string when there is no more data, fread will return false. If you are still seeing a 4K long string of zeroes, then that is a bug in the win32 bz2 library. ------------------------------------------------------------------------ [2002-04-19 23:32:40] joshbuddy@hotmail.com this does not work on win32. bzread gives back a string of \0 as long as the bzread requested... and in php "\0\0\0" != false i'm going to reopen and mark it as a win32 bug until there is confirmation.. good luck. ------------------------------------------------------------------------ [2002-04-18 18:41:09] wez@php.net Err, scratch that last comment; the only way to detect eof for bzip streams is to keep reading it. feof will always return false for bz2. Your bzread or fread call should return false when no more data can be read. while(($string = bzread($bzfile, 4096)) !== false) { ... } should do what you want. ------------------------------------------------------------------------ [2002-04-18 18:35:27] wez@php.net Try a recent CVS snapshot; you can now use feof on bz handles. Reopen this report if it doesn't work for you :-) ------------------------------------------------------------------------ [2002-04-18 17:29:05] joshbuddy@hotmail.com obviously feof will not work on a Bz file handle (though it would be nice if it did) the only way i could find it detect the end in a loop (where you would be slurping in the whole file) is: // open the file ... $bzfile $data=""; $string=bzread($bzfile,4096); while ($string!=str_repeat("\0",4096)) { $data.=$string; $string=bzread($bzfile,4096); } a better mechanism for eof detection is needed ------------------------------------------------------------------------ -- Edit this bug report at http://bugs.php.net/?id=16689&edit=1

« previous php.bugs (#18215) next »