Debian Codegraph @

vendor/wikimedia/shellbox/src/Command/InputFileFromStream.php

raw
1 <?php
2
3 namespace Shellbox\Command;
4
5 use GuzzleHttp\Psr7\Utils;
6 use Psr\Http\Message\StreamInterface;
7 use Shellbox\FileUtils;
8
9 class InputFileFromStream extends InputFileWithContents {
10 /** @var StreamInterface */
11 private $stream;
12
13 /**
14 * @internal
15 * @param StreamInterface $stream
16 */
17 public function __construct( StreamInterface $stream ) {
18 $this->stream = $stream;
19 }
20
21 public function copyTo( $destPath ) {
22 // Rewind for consistency with getStreamOrString()
23 $this->stream->rewind();
24 Utils::copyToStream( $this->stream, FileUtils::openOutputFileStream( $destPath ) );
25 }
26
27 public function getStreamOrString() {
28 // The client needs to read it twice.
29 // Rewind, otherwise we may get different results each time.
30 $this->stream->rewind();
31 return $this->stream;
32 }
33 }