Skip to content

Commit

Permalink
Modify S3 Stream Wrapper to work with PHP 7+ for empty file uploads
Browse files Browse the repository at this point in the history
  • Loading branch information
howardlopez committed Mar 1, 2019
1 parent a926b9a commit c33009a
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions src/S3/StreamWrapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,8 @@ class StreamWrapper
/** @var string The opened protocol (e.g., "s3") */
private $protocol = 's3';

private $isFlushed = false;

/**
* Register the 's3://' stream wrapper
*
Expand Down Expand Up @@ -127,12 +129,16 @@ public static function register(

public function stream_close()
{
if ($this->body->getSize() === 0 && !($this->isFlushed)) {
$this->stream_flush();
}
$this->body = $this->cache = null;
}

public function stream_open($path, $mode, $options, &$opened_path)
{
$this->initProtocol($path);
$this->isFlushed = false;
$this->params = $this->getBucketKey($path);
$this->mode = rtrim($mode, 'bt');

Expand All @@ -156,6 +162,7 @@ public function stream_eof()

public function stream_flush()
{
$this->isFlushed = true;
if ($this->mode == 'r') {
return false;
}
Expand Down

0 comments on commit c33009a

Please sign in to comment.