diff --git a/src/XmlReader.php b/src/XmlReader.php index ac72b83..ed15a8e 100644 --- a/src/XmlReader.php +++ b/src/XmlReader.php @@ -131,12 +131,26 @@ public static function fromPsrResponse(MessageInterface $response): static throw new XmlReaderException('Unable to create the temporary file.'); } + $isStreamSeekable = $stream->isSeekable(); + + // Rewind before reading + + if ($isStreamSeekable === true) { + $stream->rewind(); + } + while (! $stream->eof()) { if ($bytes = $stream->read(1024)) { fwrite($temporaryFile, $bytes); } } + // Rewind after reading + + if ($isStreamSeekable === true) { + $stream->rewind(); + } + rewind($temporaryFile); return new static(