public static function copyToStream(StreamInterface $source, StreamInterface $dest, int $maxLen = -1): void
    {
        if ($maxLen === -1) {
            while (! $source->eof()) {
                if (! (bool) $dest->write($source->read(1048576))) {
                    break;
                }
            }

            return;
        }

        $bufferSize = 8192;

        if ($maxLen === -1) {
            while (! $source->eof()) {
                if (! (bool) $dest->write($source->read($bufferSize))) {
                    break;
                }
            }
        } else {
            $remaining = $maxLen;

            while ($remaining > 0 && ! $source->eof()) {
                $buf = $source->read(\min($bufferSize, $remaining));
                $len = \strlen($buf);

                if (! $len) {
                    break;
                }

                $remaining -= $len;
                $dest->write($buf);
            }
        }
    }
public static function copyToStream(StreamInterface $source, StreamInterface $dest, int $maxLen = -1): void
    {
        if ($maxLen === -1) {
            while (! $source->eof()) {
                if (! (bool) $dest->write($source->read(1048576))) {
                    break;
                }
            }

            return;
        }

        $bufferSize = 8192;

        if ($maxLen === -1) {
            while (! $source->eof()) {
                if (! (bool) $dest->write($source->read($bufferSize))) {
                    break;
                }
            }
        } else {
            $remaining = $maxLen;

            while ($remaining > 0 && ! $source->eof()) {
                $buf = $source->read(\min($bufferSize, $remaining));
                $len = \strlen($buf);

                if (! $len) {
                    break;
                }

                $remaining -= $len;
                $dest->write($buf);
            }
        }
    }
public static function copyToStream ( StreamInterface $ source , StreamInterface $ dest , int $ maxLen = - 1 ) : void { if ( $ maxLen === - 1 ) { while ( ! $ source -> eof ( ) ) { if ( ! ( bool ) $ dest -> write ( $ source -> read ( 1048576 ) ) ) { break ; } } return ; } $ bufferSize = 8192 ; if ( $ maxLen === - 1 ) { while ( ! $ source -> eof ( ) ) { if ( ! ( bool ) $ dest -> write ( $ source -> read ( $ bufferSize ) ) ) { break ; } } } else { $ remaining = $ maxLen ; while ( $ remaining > 0 && ! $ source -> eof ( ) ) { $ buf = $ source -> read ( \ min ( $ bufferSize , $ remaining ) ) ; $ len = \ strlen ( $ buf ) ; if ( ! $ len ) { break ; } $ remaining -= $ len ; $ dest -> write ( $ buf ) ; } } }
Copy the contents of a stream into another stream until the given number
of bytes have been read.

@param \Psr\Http\Message\StreamInterface $source Stream to read from
@param \Psr\Http\Message\StreamInterface $dest   Stream to write to
@param int                               $maxLen Maximum number of bytes to read. Pass -1
to read the entire stream.

@throws \RuntimeException
Copy the contents of a stream into another stream until the given number of bytes have been read .