use Nodes API for zip streaming
Signed-off-by: Arthur Schiwon <blizzz@arthur-schiwon.de>
This commit is contained in:
parent
38184ca9fd
commit
2989732597
|
@ -24,6 +24,12 @@
|
||||||
|
|
||||||
namespace OC;
|
namespace OC;
|
||||||
|
|
||||||
|
use OC\Files\Filesystem;
|
||||||
|
use OCP\Files\File;
|
||||||
|
use OCP\Files\Folder;
|
||||||
|
use OCP\Files\InvalidPathException;
|
||||||
|
use OCP\Files\NotFoundException;
|
||||||
|
use OCP\Files\NotPermittedException;
|
||||||
use OCP\IRequest;
|
use OCP\IRequest;
|
||||||
use ownCloud\TarStreamer\TarStreamer;
|
use ownCloud\TarStreamer\TarStreamer;
|
||||||
use ZipStreamer\ZipStreamer;
|
use ZipStreamer\ZipStreamer;
|
||||||
|
@ -88,10 +94,12 @@ class Streamer {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Stream directory recursively
|
* Stream directory recursively
|
||||||
* @param string $dir
|
*
|
||||||
* @param string $internalDir
|
* @throws NotFoundException
|
||||||
|
* @throws NotPermittedException
|
||||||
|
* @throws InvalidPathException
|
||||||
*/
|
*/
|
||||||
public function addDirRecursive($dir, $internalDir='') {
|
public function addDirRecursive(string $dir, string $internalDir = ''): void {
|
||||||
$dirname = basename($dir);
|
$dirname = basename($dir);
|
||||||
$rootDir = $internalDir . $dirname;
|
$rootDir = $internalDir . $dirname;
|
||||||
if (!empty($rootDir)) {
|
if (!empty($rootDir)) {
|
||||||
|
@ -101,18 +109,23 @@ class Streamer {
|
||||||
// prevent absolute dirs
|
// prevent absolute dirs
|
||||||
$internalDir = ltrim($internalDir, '/');
|
$internalDir = ltrim($internalDir, '/');
|
||||||
|
|
||||||
$files= \OC\Files\Filesystem::getDirectoryContent($dir);
|
$userFolder = \OC::$server->getRootFolder()->get(Filesystem::getRoot());
|
||||||
|
/** @var Folder $dirNode */
|
||||||
|
$dirNode = $userFolder->get($rootDir);
|
||||||
|
$files = $dirNode->getDirectoryListing();
|
||||||
|
|
||||||
foreach($files as $file) {
|
foreach($files as $file) {
|
||||||
$filename = $file['name'];
|
if($file instanceof File) {
|
||||||
$file = $dir . '/' . $filename;
|
$fh = $file->fopen('r');
|
||||||
if(\OC\Files\Filesystem::is_file($file)) {
|
$this->addFileFromStream(
|
||||||
$filesize = \OC\Files\Filesystem::filesize($file);
|
$fh,
|
||||||
$fileTime = \OC\Files\Filesystem::filemtime($file);
|
$internalDir . $file->getName(),
|
||||||
$fh = \OC\Files\Filesystem::fopen($file, 'r');
|
$file->getSize(),
|
||||||
$this->addFileFromStream($fh, $internalDir . $filename, $filesize, $fileTime);
|
$file->getMTime()
|
||||||
|
);
|
||||||
fclose($fh);
|
fclose($fh);
|
||||||
}elseif(\OC\Files\Filesystem::is_dir($file)) {
|
} elseif ($file instanceof Folder) {
|
||||||
$this->addDirRecursive($file, $internalDir);
|
$this->addDirRecursive($file->getName(), $internalDir);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue