Skip to content

Commit

Permalink
Merge pull request #22 from saloonphp/fix/rewind-stream-before-accessing
Browse files Browse the repository at this point in the history
Fix | Rewind Stream Before Accessing
  • Loading branch information
Sammyjo20 authored Dec 2, 2023
2 parents c2a7552 + f2fb55c commit fa9f5b0
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions src/XmlReader.php
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down

0 comments on commit fa9f5b0

Please sign in to comment.