diff --git a/src/GitlabAdapter.php b/src/GitlabAdapter.php index 00c4f28..9633206 100644 --- a/src/GitlabAdapter.php +++ b/src/GitlabAdapter.php @@ -147,7 +147,17 @@ public function read(string $path): string */ public function readStream(string $path) { - throw new UnableToCreateStream(get_class($this).' Gitlab API does not support reading a file into a stream.'); + if (false === ($fp = fopen('php://memory', 'r+'))) { + throw UnableToReadFile::fromLocation($path, 'Unable to open memory stream'); + } + + if (false === fwrite($fp, $this->read($path))) { + throw UnableToReadFile::fromLocation($path, 'Unable to write stream'); + } + + fseek($fp, 0); + + return $fp; } /** diff --git a/src/UnableToCreateStream.php b/src/UnableToCreateStream.php deleted file mode 100644 index 7bdea3e..0000000 --- a/src/UnableToCreateStream.php +++ /dev/null @@ -1,24 +0,0 @@ -expectException(UnableToCreateStream::class); + $stream = $this->gitlabAdapter->readStream('README.md'); - $this->gitlabAdapter->readStream('README.md'); + $this->assertIsResource($stream); + $this->assertEquals(stream_get_contents($stream, null, 0), $this->gitlabAdapter->read('README.md')); } /**