You are here

function copy_to_stream in Auth0 Single Sign On 8.2

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

Parameters

StreamInterface $source Stream to read from:

StreamInterface $dest Stream to write to:

int $maxLen Maximum number of bytes to read. Pass -1: to read the entire stream.

Throws

\RuntimeException on error.

2 calls to copy_to_stream()
CachingStream::cacheEntireStream in vendor/guzzlehttp/psr7/src/CachingStream.php
UploadedFile::moveTo in vendor/guzzlehttp/psr7/src/UploadedFile.php

File

vendor/guzzlehttp/psr7/src/functions.php, line 373

Namespace

GuzzleHttp\Psr7

Code

function copy_to_stream(StreamInterface $source, StreamInterface $dest, $maxLen = -1) {
  $bufferSize = 8192;
  if ($maxLen === -1) {
    while (!$source
      ->eof()) {
      if (!$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);
    }
  }
}