/** * @param $filePath * @param $toBeDownloadedFileName * * @return int */ public function downloadAttachment($filePath, $toBeDownloadedFileName = '') { if (!is_readable($this->currentPath . $filePath)) { $this->setError(self::ERROR_ATTACHMENT_FILE_DOES_NOT_EXIST); } if (empty($toBeDownloadedFileName)) { $toBeDownloadedFileName = basename($filePath); if (empty($toBeDownloadedFileName)) { $this->setError(self::ERROR_ATTACHMENT_DOES_NOT_EXIST); } } if ($this->hasError()) { return $this->errors; } $this->setHeadersForAttachmentDownload($toBeDownloadedFileName); if ($this->fileSystem->getSize($filePath) > DirectoryStructure::FS_DOWNLOAD_STREAM_AFTER_SIZE) { header('Content-Length: ' . $this->fileSystem->getSize($filePath)); $stream = $this->fileSystem->readStream($filePath); while (!feof($stream)) { print fgets($stream, 1024); flush(); } fclose($stream); exit; } else { ob_start(); ob_start("ob_gzhandler"); echo $this->fileSystem->get($filePath)->read(); ob_end_flush(); $gzippedContent = ob_get_contents(); // store gzipped content to get size header('Content-Length: ' . strlen($gzippedContent)); ob_end_flush(); exit; } }
/** * {@inheritdoc} */ public function getArchive(JobExecution $jobExecution, $key) { $archives = $this->getArchives($jobExecution); if (!isset($archives[$key])) { throw new \InvalidArgumentException(sprintf('Key "%s" does not exist', $key)); } return $this->filesystem->readStream($archives[$key]); }
public function testReadStream() { $adapter = Mockery::mock('League\\Flysystem\\AdapterInterface'); $adapter->shouldReceive('has')->andReturn(true); $adapter->shouldReceive('readStream')->twice()->andReturn(array('stream' => 'this result'), false); $filesystem = new Filesystem($adapter); $this->assertEquals('this result', $filesystem->readStream('file.txt')); $this->assertFalse($filesystem->readStream('other.txt')); // Another time to hit the cache $this->assertEquals('this result', $filesystem->readStream('file.txt')); }
public function testReadStream() { $adapter = Mockery::mock('League\\Flysystem\\AdapterInterface'); $adapter->shouldReceive('has')->andReturn(true); $stream = tmpfile(); $adapter->shouldReceive('readStream')->times(3)->andReturn(['stream' => $stream], false, false); $filesystem = new Filesystem($adapter); $this->assertInternalType('resource', $filesystem->readStream('file.txt')); $this->assertFalse($filesystem->readStream('other.txt')); fclose($stream); $this->assertFalse($filesystem->readStream('other.txt')); }
function it_should_execute_the_transfer_file_command(Filesystem $source, Filesystem $destination) { $source->readStream('source')->willReturn('data'); $destination->writeStream('destination', 'data')->shouldBeCalled(); $this->beConstructedWith($source, 'source', $destination, 'destination'); $this->execute(); }
public function testReadStreamFail() { $path = 'path.txt'; $this->prophecy->has($path)->willReturn(true); $this->prophecy->readStream($path)->willReturn(false); $response = $this->filesystem->readStream($path); $this->assertFalse($response); }
/** * @inheritdoc */ public function readStream($path) { try { return $this->fileSystem->readStream($this->getInnerPath($path)); } catch (FileNotFoundException $e) { throw $this->exceptionWrapper($e, $path); } }
public function testPushNotExists() { $file = '123-123-123'; $path = sprintf('%s/%s.zip', $this->name, $file); $this->localFilesystem->readStream($path)->willReturn(false); $this->remoteFilesystem->putStream($path, Argument::any())->shouldNotBeCalled(); $this->storage->push($file); }
/** * {@inheritdoc} */ public function push($file) { if (!$this->remoteFilesystem) { throw new RemoteStorageNotConfiguredException(); } $path = sprintf('%s/%s.zip', $this->name, $file); if (false === ($stream = $this->localFilesystem->readStream($path)) || $this->remoteFilesystem->has($path)) { return; } $this->remoteFilesystem->putStream($path, $stream); }
/** * Deploy files to the remote filesystem. * * @return void */ public function deployToRemote() { $local_path = $this->relativeDumpPath(); $files = $this->localAdapter->listContents($local_path); foreach ($files as $file) { $contents = $this->localAdapter->readStream($local_path . $file['basename']); $file_size = $this->localAdapter->getSize($local_path . $file['basename']); $this->out($this->parseString('Uploading %s (%s)', [$file['basename'], $this->formatBytes($file_size)], 'light_green')); $this->remoteAdapter->writeStream($local_path . $file['basename'], $contents); } }
/** * {@inheritdoc} */ public function fopen($path, $mode) { $fullPath = $this->buildPath($path); $useExisting = true; switch ($mode) { case 'r': case 'rb': try { return $this->flysystem->readStream($fullPath); } catch (FileNotFoundException $e) { return false; } case 'w': case 'w+': case 'wb': case 'wb+': $useExisting = false; case 'a': case 'ab': case 'r+': case 'a+': case 'x': case 'x+': case 'c': case 'c+': //emulate these if ($useExisting and $this->file_exists($path)) { if (!$this->isUpdatable($path)) { return false; } $tmpFile = $this->getCachedFile($path); } else { if (!$this->isCreatable(dirname($path))) { return false; } $tmpFile = \OCP\Files::tmpFile(); } $source = fopen($tmpFile, $mode); return CallbackWrapper::wrap($source, null, null, function () use($tmpFile, $fullPath) { $this->flysystem->putStream($fullPath, fopen($tmpFile, 'r')); unlink($tmpFile); }); } return false; }
function it_should_unsuccessfully_read_stream_from_remote_file($path, Filesystem $filesystem) { $filesystem->readStream($path)->willReturn(false); $this->readStream($path)->shouldReturn(false); $filesystem->readStream($path)->shouldBeCalled(); }
public function testReadStream() { $this->assertInternalType('resource', $this->filesystem->readStream('2.txt')); }
/** * Moves a file from somewhere to the expired trash heap * * @param Filesystem $filesystem * @param string $filename * @param array $config An optional configuration array * * @return bool */ protected function moveToTrash(Filesystem $filesystem, $filename, array $config = []) { if (config('snapshot.soft-delete', EnterpriseDefaults::SNAPSHOT_SOFT_DELETE)) { $_trash = InstanceStorage::getTrashMount('expired'); if ($_trash->writeStream($filename, $filesystem->readStream($filename), $config)) { return $filesystem->delete($filename); } // Try and remove any partial file created before failure try { $_trash->delete($filename); } catch (\Exception $_ex) { // Ignored, this is a cleanup in case of failure... } } else { try { if ($filesystem->has($filename)) { return $filesystem->delete($filename); } // It's gone return true; } catch (\Exception $_ex) { // Can't delete? not good return false; } } return false; }
/** * @throws \InvalidArgumentException */ public function execute() { $this->destinationFilesystem->writeStream($this->destinationPath, $this->sourceFilesystem->readStream($this->sourcePath)); }
public function readStream($path) { return $this->filesystem->readStream($path); }
/** * @inheritdoc */ protected function _fopen($path, $mode = "rb") { return $this->fs->readStream($path); }
public function stream($video) { if (!Auth::user()->can('view-video')) { return view('errors.denied'); } $filesystem = new Filesystem(new Adapter(base_path())); $location = '/files/video/' . $video; $stream = $filesystem->readStream($location); $headers = ["Content-Type" => $filesystem->getMimetype($location), "Content-Length" => $filesystem->getSize($location), "Content-disposition" => "attachment; filename=\"" . basename($location) . "\""]; return Response::stream(function () use($stream) { fpassthru($stream); }, 200, $headers); }
/** * {@inheritdoc} * * @throws FileExistsException * @throws \InvalidArgumentException * @throws FileNotFoundException * @throws LogicException */ public function restore(Filesystem $source, Filesystem $destination, ReadonlyDatabase $database, array $parameter) { // TODO make it smoother $files = $source->listFiles('', true); $progressBar = new ProgressBar($this->output, count($files)); $progressBar->setOverwrite(true); $progressBar->setFormat(' %current%/%max% [%bar%] %percent:3s%% %elapsed:6s%/%estimated:-6s% %memory:6s%'); $progressBar->start(); foreach ($files as $file) { $path = $file['path']; $fullPath = $parameter['directory'] . '/' . $file['path']; if ($destination->has($fullPath)) { if ($destination->hash($fullPath) === $source->hash($path)) { $progressBar->advance(); continue; } $destination->delete($fullPath); } $destination->writeStream($fullPath, $source->readStream($path)); $progressBar->advance(); } $progressBar->finish(); }