diff --git a/src/AliOssAdapter.php b/src/AliOssAdapter.php index 54d8703..08c8a47 100644 --- a/src/AliOssAdapter.php +++ b/src/AliOssAdapter.php @@ -449,10 +449,15 @@ public function read($path) public function readStream($path) { $result = $this->readObject($path); - $result['stream'] = $result['raw_contents']; + if (is_resource($result['raw_contents'])) { + $result['stream'] = $result['raw_contents']; + // Ensure the EntityBody object destruction doesn't close the stream + $result['raw_contents']->detachStream(); + } else { + $result['stream'] = fopen('php://temp', 'r+'); + fwrite($result['stream'], $result['raw_contents']); + } rewind($result['stream']); - // Ensure the EntityBody object destruction doesn't close the stream - $result['raw_contents']->detachStream(); unset($result['raw_contents']); return $result;