Esempio n. 1
0
 public function testChecksEof()
 {
     $handle = fopen('php://temp', 'w+');
     fwrite($handle, 'data');
     $stream = new Stream($handle);
     $this->assertFalse($stream->eof());
     $stream->read(4);
     $this->assertTrue($stream->eof());
     $stream->close();
 }
Esempio n. 2
0
 /**
  * Download a given File.
  *
  * @param mixed $file File Location or Resource
  *
  * @return resource
  */
 protected function downloadFile($file)
 {
     if (!is_resource($file)) {
         $file = fopen($file, 'r');
     }
     $stream = new Stream($file);
     $downloadedFile = fopen('php://temp', 'w+');
     if ($downloadedFile === false) {
         throw new \Exception('Error when saving the downloaded file');
     }
     while (!$stream->eof()) {
         $writeResult = fwrite($downloadedFile, $stream->read(8000));
         if ($writeResult === false) {
             throw new \Exception('Error when saving the downloaded file');
         }
     }
     $stream->close();
     rewind($downloadedFile);
     return $downloadedFile;
 }