DummyFileSystemStream.php 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  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. /**
  11. * @param $path
  12. * @param $mode
  13. * @param $options
  14. * @param $opened_path
  15. *
  16. * @return bool
  17. */
  18. public function stream_open($path, $mode, $options, &$opened_path)
  19. {
  20. $parsedUrl = parse_url($path);
  21. $path = $parsedUrl['path'];
  22. $this->fp = fopen($path, $mode);
  23. return true;
  24. }
  25. /**
  26. * @param $count
  27. *
  28. * @return false|string
  29. */
  30. public function stream_read($count)
  31. {
  32. return fread($this->fp, $count);
  33. }
  34. /**
  35. * @return false|int
  36. */
  37. public function stream_tell()
  38. {
  39. return ftell($this->fp);
  40. }
  41. /**
  42. * @return bool
  43. */
  44. public function stream_eof()
  45. {
  46. return feof($this->fp);
  47. }
  48. /**
  49. * @param $offset
  50. * @param $whence
  51. */
  52. public function stream_seek($offset, $whence)
  53. {
  54. fseek($this->fp, $offset, $whence);
  55. }
  56. /**
  57. * @return array
  58. */
  59. public function stream_stat()
  60. {
  61. return fstat($this->fp);
  62. }
  63. }