📂 File Browser

AgentAI/vendor/guzzlehttp/psr7/src
🌙 Dark Mode
🎯 Quick Launch:

📁 Directories

📁 Exception/ 🔓 Open

📄 Files

🐘 AppendStream.php
▶ Open 📄 View Source
🐘 BufferStream.php
▶ Open 📄 View Source
🐘 CachingStream.php
▶ Open 📄 View Source
🐘 DroppingStream.php
▶ Open 📄 View Source
🐘 FnStream.php
▶ Open 📄 View Source
🐘 Header.php
▶ Open 📄 View Source
🐘 HttpFactory.php
▶ Open 📄 View Source
🐘 InflateStream.php
▶ Open 📄 View Source
🐘 LazyOpenStream.php
▶ Open 📄 View Source
🐘 LimitStream.php
▶ Open 📄 View Source
🐘 Message.php
▶ Open 📄 View Source
🐘 MessageTrait.php
▶ Open 📄 View Source
🐘 MimeType.php
▶ Open 📄 View Source
🐘 MultipartStream.php
▶ Open 📄 View Source
🐘 NoSeekStream.php
▶ Open 📄 View Source
🐘 PumpStream.php
▶ Open 📄 View Source
🐘 Query.php
▶ Open 📄 View Source
🐘 Request.php
▶ Open 📄 View Source
🐘 Response.php
▶ Open 📄 View Source
🐘 Rfc7230.php
▶ Open 📄 View Source
🐘 ServerRequest.php
▶ Open 📄 View Source
🐘 Stream.php
▶ Open 📄 View Source
🐘 StreamDecoratorTrait.php
▶ Open 📄 View Source
🐘 StreamWrapper.php
▶ Open 📄 View Source
🐘 UploadedFile.php
▶ Open 📄 View Source
🐘 Uri.php
▶ Open 📄 View Source
🐘 UriComparator.php
▶ Open 📄 View Source
🐘 UriNormalizer.php
▶ Open 📄 View Source
🐘 UriResolver.php
▶ Open 📄 View Source
🐘 Utils.php
▶ Open 📄 View Source

📄 Source: DroppingStream.php

<?php

declare(strict_types=1);

namespace GuzzleHttp\Psr7;

use Psr\Http\Message\StreamInterface;

/**
 * Stream decorator that begins dropping data once the size of the underlying
 * stream becomes too full.
 */
final class DroppingStream implements StreamInterface
{
    use StreamDecoratorTrait;

    /** @var int */
    private $maxLength;

    /** @var StreamInterface */
    private $stream;

    /**
     * @param StreamInterface $stream    Underlying stream to decorate.
     * @param int             $maxLength Maximum size before dropping data.
     */
    public function __construct(StreamInterface $stream, int $maxLength)
    {
        $this->stream = $stream;
        $this->maxLength = $maxLength;
    }

    public function write($string): int
    {
        $diff = $this->maxLength - $this->stream->getSize();

        // Begin returning 0 when the underlying stream is too large.
        if ($diff <= 0) {
            return 0;
        }

        // Write the stream or a subset of the stream if needed.
        if (strlen($string) < $diff) {
            return $this->stream->write($string);
        }

        return $this->stream->write(substr($string, 0, $diff));
    }
}
← Back