CoreFiles by mySites.guru
DroppingStream.php49 lines, 1,196 bytes, from Joomla_5.2.0-beta1-Beta-Full_Package.zip
Raw History Compare with 5.1.0-beta2
md5
e54ea06e8af801260f8f7c1ef02dda53
sha1
d565a438ab74b95333cf38497f5edb3826dc03f3
sha256
af6ae45881fda23f2160c9d4ed38c13d6890c8e12fe4263763facd189e9deb42
<?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));
    }
}

The same content is in 106 releases, Joomla 5.1.0-beta1 to 6.2.0-alpha1. See them all, or every version of this file.