original_string: public function withFile($path, array $options = [])
      {
          $file = $this->validateFile($path);
          $options += [
              'name' => null,
              'download' => null
          ];
  
          $extension = strtolower($file->ext());
          $mapped = $this->getMimeType($extension);
          if ((!$extension || !$mapped) && $options['download'] === null) {
              $options['download'] = true;
          }
  
          $new = clone $this;
          if ($mapped) {
              $new = $new->withType($extension);
          }
  
          $fileSize = $file->size();
          if ($options['download']) {
              $agent = env('HTTP_USER_AGENT');
  
              if (preg_match('%Opera(/| )([0-9].[0-9]{1,2})%', $agent)) {
                  $contentType = 'application/octet-stream';
              } elseif (preg_match('/MSIE ([0-9].[0-9]{1,2})/', $agent)) {
                  $contentType = 'application/force-download';
              }
  
              if (isset($contentType)) {
                  $new = $new->withType($contentType);
              }
              $name = $options['name'] ?: $file->name;
              $new = $new->withDownload($name)
                  ->withHeader('Content-Transfer-Encoding', 'binary');
          }
  
          $new = $new->withHeader('Accept-Ranges', 'bytes');
          $httpRange = env('HTTP_RANGE');
          if (isset($httpRange)) {
              $new->_fileRange($file, $httpRange);
          } else {
              $new = $new->withHeader('Content-Length', (string)$fileSize);
          }
          $new->_file = $file;
          $new->stream = new Stream($file->path, 'rb');
  
          return $new;
      }
code: public function withFile($path, array $options = [])
      {
          $file = $this->validateFile($path);
          $options += [
              'name' => null,
              'download' => null
          ];
  
          $extension = strtolower($file->ext());
          $mapped = $this->getMimeType($extension);
          if ((!$extension || !$mapped) && $options['download'] === null) {
              $options['download'] = true;
          }
  
          $new = clone $this;
          if ($mapped) {
              $new = $new->withType($extension);
          }
  
          $fileSize = $file->size();
          if ($options['download']) {
              $agent = env('HTTP_USER_AGENT');
  
              if (preg_match('%Opera(/| )([0-9].[0-9]{1,2})%', $agent)) {
                  $contentType = 'application/octet-stream';
              } elseif (preg_match('/MSIE ([0-9].[0-9]{1,2})/', $agent)) {
                  $contentType = 'application/force-download';
              }
  
              if (isset($contentType)) {
                  $new = $new->withType($contentType);
              }
              $name = $options['name'] ?: $file->name;
              $new = $new->withDownload($name)
                  ->withHeader('Content-Transfer-Encoding', 'binary');
          }
  
          $new = $new->withHeader('Accept-Ranges', 'bytes');
          $httpRange = env('HTTP_RANGE');
          if (isset($httpRange)) {
              $new->_fileRange($file, $httpRange);
          } else {
              $new = $new->withHeader('Content-Length', (string)$fileSize);
          }
          $new->_file = $file;
          $new->stream = new Stream($file->path, 'rb');
  
          return $new;
      }
code_tokens: public function withFile ( $ path , array $ options = [ ] ) { $ file = $ this -> validateFile ( $ path ) ; $ options += [ 'name' => null , 'download' => null ] ; $ extension = strtolower ( $ file -> ext ( ) ) ; $ mapped = $ this -> getMimeType ( $ extension ) ; if ( ( ! $ extension || ! $ mapped ) && $ options [ 'download' ] === null ) { $ options [ 'download' ] = true ; } $ new = clone $ this ; if ( $ mapped ) { $ new = $ new -> withType ( $ extension ) ; } $ fileSize = $ file -> size ( ) ; if ( $ options [ 'download' ] ) { $ agent = env ( 'HTTP_USER_AGENT' ) ; if ( preg_match ( '%Opera(/| )([0-9].[0-9]{1,2})%' , $ agent ) ) { $ contentType = 'application/octet-stream' ; } elseif ( preg_match ( '/MSIE ([0-9].[0-9]{1,2})/' , $ agent ) ) { $ contentType = 'application/force-download' ; } if ( isset ( $ contentType ) ) { $ new = $ new -> withType ( $ contentType ) ; } $ name = $ options [ 'name' ] ? : $ file -> name ; $ new = $ new -> withDownload ( $ name ) -> withHeader ( 'Content-Transfer-Encoding' , 'binary' ) ; } $ new = $ new -> withHeader ( 'Accept-Ranges' , 'bytes' ) ; $ httpRange = env ( 'HTTP_RANGE' ) ; if ( isset ( $ httpRange ) ) { $ new -> _fileRange ( $ file , $ httpRange ) ; } else { $ new = $ new -> withHeader ( 'Content-Length' , ( string ) $ fileSize ) ; } $ new -> _file = $ file ; $ new -> stream = new Stream ( $ file -> path , 'rb' ) ; return $ new ; }
docstring: Create a new instance that is based on a file.
  
  This method will augment both the body and a number of related headers.
  
  If `$_SERVER['HTTP_RANGE']` is set, a slice of the file will be
  returned instead of the entire file.
  
  ### Options keys
  
  - name: Alternate download name
  - download: If `true` sets download header and forces file to
  be downloaded rather than displayed inline.
  
  @param string $path Path to file. If the path is not an absolute path that resolves
  to a file, `APP` will be prepended to the path (this behavior is deprecated).
  @param array $options Options See above.
  @return static
  @throws \Cake\Http\Exception\NotFoundException
docstring_tokens: Create a new instance that is based on a file .