Use zip32 if possible

* OSX doesn't handle 64zip that well
* Some other implentations don't handle it perfectly either
* If the file is belog 4GiB (some overhead) => zip32
* This covers the 99% case I bet

Signed-off-by: Roeland Jago Douma <roeland@famdouma.nl>
This commit is contained in:
Roeland Jago Douma 2018-01-20 11:41:04 +01:00
parent e970e9f710
commit 4a73f645e5
No known key found for this signature in database
GPG Key ID: F941078878347C0C
2 changed files with 31 additions and 9 deletions

View File

@ -24,6 +24,7 @@
namespace OC;
use OCP\IRequest;
use ownCloud\TarStreamer\TarStreamer;
use ZipStreamer\ZipStreamer;
@ -33,12 +34,22 @@ class Streamer {
// streamer instance
private $streamerInstance;
public function __construct(){
/** @var \OCP\IRequest */
$request = \OC::$server->getRequest();
if ($request->isUserAgent($this->preferTarFor)) {
/**
* Streamer constructor.
*
* @param IRequest $request
* @param int $size The size of the files in bytes
*/
public function __construct(IRequest $request, int $size){
/**
* If the size if below 4GB always use zip32
* Use 4*1000*1000*1000 so we have a buffer for all the extra zip data
*/
if ($size < 4 * 1000 * 1000 * 1000) {
$this->streamerInstance = new ZipStreamer(['zip64' => false]);
} else if ($request->isUserAgent($this->preferTarFor)) {
$this->streamerInstance = new TarStreamer();
} else {
$this->streamerInstance = new ZipStreamer(['zip64' => PHP_INT_SIZE !== 4]);

View File

@ -144,17 +144,28 @@ class OC_Files {
}
}
$streamer = new Streamer();
OC_Util::obEnd();
self::lockFiles($view, $dir, $files);
/* Calculate filesize */
if ($getType === self::ZIP_FILES) {
$fileSize = 0;
foreach ($files as $file) {
$fileSize += \OC\Files\Filesystem::getFileInfo($dir . '/' . $file)->getSize();
}
} elseif ($getType === self::ZIP_DIR) {
$fileSize = \OC\Files\Filesystem::getFileInfo($dir . '/' . $files)->getSize();
}
$streamer = new Streamer(\OC::$server->getRequest(), $fileSize);
OC_Util::obEnd();
$streamer->sendHeaders($name);
$executionTime = (int)OC::$server->getIniWrapper()->getNumeric('max_execution_time');
if (strpos(@ini_get('disable_functions'), 'set_time_limit') === false) {
@set_time_limit(0);
}
ignore_user_abort(true);
if ($getType === self::ZIP_FILES) {
foreach ($files as $file) {
$file = $dir . '/' . $file;