Skip to content

Commit

Permalink
feat: create a seekable stream when reading. Allows http range reques…
Browse files Browse the repository at this point in the history
…ts which is necessary for video playback
  • Loading branch information
DeepDiver1975 committed Dec 14, 2021
1 parent 56825cb commit 9095ce9
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions lib/s3storage.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ public function __construct($params) {
$this->params = $params;
}

protected function init() {
protected function init(): void {
if ($this->connection) {
return;
}
Expand Down Expand Up @@ -178,7 +178,10 @@ public function deleteObject($urn) {
public function readObject($urn) {
$this->init();
try {
return \fopen($this->getUrl($urn), 'r');
$context = stream_context_create([
'seekable' => true
]);
return \fopen($this->getUrl($urn), 'rb', null, $context);
} catch (AwsException $ex) {
throw new ObjectStoreOperationException($ex->getAwsErrorMessage(), $ex->getStatusCode(), $ex);
}
Expand Down Expand Up @@ -275,7 +278,11 @@ public function getVersion($urn, $versionId) {
public function getContentOfVersion($urn, $versionId) {
$this->init();
try {
return \fopen($this->getUrl($urn, $versionId), 'r');
$context = stream_context_create([
'seekable' => true
]);

return \fopen($this->getUrl($urn, $versionId), 'rb', null, $context);
} catch (AwsException $ex) {
throw new ObjectStoreOperationException($ex->getAwsErrorMessage(), $ex->getStatusCode(), $ex);
}
Expand Down

0 comments on commit 9095ce9

Please sign in to comment.