FileReader

The WordPress Core FileReader class.

Defined (1)

The class is defined in the following location(s).

/streams.php  
  1. class FileReader { 
  2. var $_pos; 
  3. var $_fd; 
  4. var $_length; 
  5.  
  6. function FileReader($filename) { 
  7. if (file_exists($filename)) { 
  8.  
  9. $this->_length=filesize($filename); 
  10. $this->_pos = 0; 
  11. $this->_fd = fopen($filename, 'rb'); 
  12. if (!$this->_fd) { 
  13. $this->error = 3; // Cannot read file, probably permissions 
  14. return false; 
  15. } else { 
  16. $this->error = 2; // File doesn't exist 
  17. return false; 
  18.  
  19. function read($bytes) { 
  20. if ($bytes) { 
  21. fseek($this->_fd, $this->_pos); 
  22.  
  23. $data = ''; 
  24.  
  25. // PHP 5.1.1 does not read more than 8192 bytes in one fread() 
  26. // the discussions at PHP Bugs suggest it's the intended behaviour 
  27. while ($bytes > 0) { 
  28. $chunk = fread($this->_fd, $bytes); 
  29. $data .= $chunk; 
  30. $bytes -= strlen($chunk); 
  31. $this->_pos = ftell($this->_fd); 
  32.  
  33. return $data; 
  34. } else return ''; 
  35.  
  36. function seekto($pos) { 
  37. fseek($this->_fd, $pos); 
  38. $this->_pos = ftell($this->_fd); 
  39. return $this->_pos; 
  40.  
  41. function currentpos() { 
  42. return $this->_pos; 
  43.  
  44. function length() { 
  45. return $this->_length; 
  46.  
  47. function close() { 
  48. fclose($this->_fd); 
  49.