Skip to content

Commit

Permalink
🚑 Rewind streams before getting contents to prevent it from returning…
Browse files Browse the repository at this point in the history
… empty strings
  • Loading branch information
Shady Khattab committed Dec 27, 2017
1 parent a838ada commit 33a2179
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/Resources/File.php
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,9 @@ public function getBase64Data($mimeType = null)
return $this->base64Data[$mimeType] = base64_encode(file_get_contents($this->paths[$mimeType]));
}
if (isset($this->streams[$mimeType])) {
// Rewind the stream to ensure that we're getting all of the contents.
$this->streams[$mimeType]->rewind();

return $this->base64Data[$mimeType] = base64_encode($this->streams[$mimeType]->getContents());
}

Expand Down
5 changes: 5 additions & 0 deletions src/Resources/Proxy/FileStreamProxy.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,11 @@ protected function getStream()
['Accept' => $this->mimeType],
MyParcelComApiInterface::TTL_MONTH
)->then(function (ResponseInterface $response) {
// Rewind the internal pointer to the start of the body. This
// prevents us from having to rewind the stream before we start
// using it.
$response->getBody()->rewind();

return $response->getBody();
})->wait();
}
Expand Down

0 comments on commit 33a2179

Please sign in to comment.