-
Notifications
You must be signed in to change notification settings - Fork 86
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' of https://github.com/paragonie/halite
- Loading branch information
Showing
5 changed files
with
171 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
<?php | ||
declare(strict_types=1); | ||
|
||
/** | ||
* Defines a fake stream wrapper for testing ReadOnlyFile operations against a stream that doesn't support fstat. | ||
*/ | ||
final class RemoteStream | ||
{ | ||
private $contents; | ||
private $position = 0; | ||
|
||
function stream_open($path, $mode, $options, &$opened_path) | ||
{ | ||
$this->contents = \file_get_contents(__DIR__ . '/tmp/' . parse_url($path, PHP_URL_HOST)); | ||
return true; | ||
} | ||
|
||
function stream_read($count) | ||
{ | ||
$return = \substr($this->contents, $this->position, $count); | ||
$this->position += strlen($return); | ||
return $return; | ||
} | ||
|
||
function stream_write($data) | ||
{ | ||
return false; | ||
} | ||
|
||
function stream_tell() | ||
{ | ||
return $this->position; | ||
} | ||
|
||
function stream_eof() | ||
{ | ||
return $this->position >= \strlen($this->contents); | ||
} | ||
|
||
function stream_seek($offset, $whence) | ||
{ | ||
switch ($whence) { | ||
case SEEK_SET: | ||
if ($offset < strlen($this->contents) && $offset >= 0) { | ||
$this->position = $offset; | ||
return true; | ||
} | ||
return false; | ||
|
||
case SEEK_CUR: | ||
if ($offset >= 0) { | ||
$this->position += $offset; | ||
return true; | ||
} | ||
return false; | ||
|
||
case SEEK_END: | ||
if (strlen($this->contents) + $offset >= 0) { | ||
$this->position = strlen($this->contents) + $offset; | ||
return true; | ||
} | ||
return false; | ||
|
||
default: | ||
return false; | ||
} | ||
} | ||
|
||
function stream_metadata($path, $option, $var) | ||
{ | ||
return false; | ||
} | ||
|
||
function stream_stat() | ||
{ | ||
return false; | ||
} | ||
|
||
} |