DummyFileSystemStream.php 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. <?php
  2. namespace PhpZip\Internal;
  3. /**
  4. * Try to load using dummy stream.
  5. */
  6. class DummyFileSystemStream
  7. {
  8. /** @var resource */
  9. private $fp;
  10. public function stream_open($path, $mode, $options, &$opened_path)
  11. {
  12. // echo "DummyFileSystemStream->stream_open($path, $mode, $options)" . PHP_EOL;
  13. $parsedUrl = parse_url($path);
  14. $path = $parsedUrl['path'];
  15. $this->fp = fopen($path, $mode);
  16. return true;
  17. }
  18. public function stream_read($count)
  19. {
  20. // echo "DummyFileSystemStream->stream_read($count)" . PHP_EOL;
  21. $position = ftell($this->fp);
  22. // echo "Loading chunk " . $position . " to " . ($position + $count - 1) . PHP_EOL;
  23. return fread($this->fp, $count);
  24. // echo "String length: " . strlen($ret) . PHP_EOL;
  25. }
  26. public function stream_tell()
  27. {
  28. // echo "DummyFileSystemStream->stream_tell()" . PHP_EOL;
  29. return ftell($this->fp);
  30. }
  31. public function stream_eof()
  32. {
  33. // echo "DummyFileSystemStream->stream_eof()" . PHP_EOL;
  34. return feof($this->fp);
  35. }
  36. public function stream_seek($offset, $whence)
  37. {
  38. // echo "DummyFileSystemStream->stream_seek($offset, $whence)" . PHP_EOL;
  39. fseek($this->fp, $offset, $whence);
  40. }
  41. public function stream_stat()
  42. {
  43. // echo "DummyFileSystemStream->stream_stat()" . PHP_EOL;
  44. return fstat($this->fp);
  45. }
  46. }