refactored/cleaned up lib/files.php and switched get() to ZipStreamer#3439
refactored/cleaned up lib/files.php and switched get() to ZipStreamer#3439McNetic wants to merge 5 commits intoowncloud:masterfrom
Conversation
cleaned up get() logic fixed get() to only send headers if requested (xsendfile could get in the way) switched zip file creation to ZipStreamer to create zip files directly in memory instead of creating (multiple) temporary files which caused heavy i/o
|
Can one of the admins verify this patch? |
|
Oh, I forgot to mention that the current implementation of ZipStreamer does not compress the zip file. It is certainly possible, but I found no easy way to do chunk-wise compression in php. |
|
@owncloud-bot this is okay to test |
|
whitespaces are totally off - please fix this - THX Conceptual question: |
|
Isn't the fact that archives are no longer compressed a huge drawback? In which scenarios is Disk I/O an issue? |
|
@owncloud-bot retest this please |
Are you telling us that the content is not zipped at all anymore? |
|
I would also like to understand the memory impact especially with huge files and a lot of users. |
|
This definitely needs discussion on your side. It certainly has some drawbacks. Maybe this should also be made optional. I'll explain why I did this: As I'm not familiar with the internals of owncloud and also not a php specialist, I can not tell if there are no major drawbacks or problems I missed, so I wanted to put the idea and the seemingly working solution to your attention. I felt that the main application of the zip functionality is to be able to download a lot of files/file hierarchies with one download. I think compression is secondary in this respect. I also felt that if the archive to be build grows large (as in several hundred mb or more), working with two temporary files per download would be an i/o problem. As for your concerns, and the pros and cons:
So, as final word: Probably, the implementation is not perfect. I'm happy to help make it better; I'm also not mad if it is completely rejected, but I think it is a direction that's worth a look at. PS: I'm not sure what is with the whitespaces. Maybe dos line endings? My tortoisegit showed the diff correctly. |
I don't think it's a problem that the files aren't compressed. I'm going to extract them after the download is complete anyways. We aren't storing the files in a zip on the server so there are no savings from compressing it if it takes longer to start the download. |
|
@McNetic thanks a lot for your detailed explanation! Much appreciated! I'll try to find some time to have a closer look at your implementation. THX |
lib/files.php
Outdated
There was a problem hiding this comment.
Bonus points for using === here.
|
Added some comments in courtesy of #2979. |
|
how does it perform for very gib files >8GB ? |
|
Can one of the admins verify this patch? |
|
@owncloud-bot this is ok to test |
|
@McNetic sorry for the long silence - can I ask you to rebase? THX |
|
Test passed. |
cleaned up get() logic fixed get() to only send headers if requested (xsendfile could get in the way) switched zip file creation to ZipStreamer to create zip files directly in memory instead of creating (multiple) temporary files which caused heavy i/o
|
I have implemented zip64 extension to ZipStreamer, which allows bigger files. You will need a newer ZIP implementation like 7z on Windows XP to extract the files. See witchi/PHPZipStreamer. It works with Owncloud 5.0.11 and PHP 5.3.17/Suhosin 0.9.33 on my side. |
|
Does ZipStreamer generate zip files with correct UTF-8 encoding ? |
|
I have tested it here with my patched OC5, and it works. I have used 中文blah中文blah as folder name and have uploaded 中文blah中文blah.txt as file. Then I have downloaded the complete folder and within my SuSE Linux I see the chinese (or whatever) characters within the zip-filename. |
|
The problem is mostly with Windows machines. See #1117 (comment) for Basically it should set the UTF-8 flag and also set the OS flag to unix |
|
On Windows XP I see only "boxes" instead of the chinese characters, but I can open the zip with 7zip and extract the files. I have installed another fork of this repository: https://github.com/witchi/PHPZipStreamer which contains UTF-8 flag and Unix-flag. It also sets some permissions. |
|
I have tested it on Windows 7 just now. The encoding is right within 7zip 9.2, but the Windows zip-support does only display the filename of the zip-file right, but the containing files and folders have wrong filenames. I can open the files, but the names are like õ©¡µûçblahõ©¡µûçblah instead of 中文blah中文blah. So it seems that Windows has problems with the UTF-8 format of zip, whereas 7zip looks good. |
|
@witchi yes, it seems that Win7 compressed folders still have issues... looks like there is nothing we can do about it. |
|
@witchi @McNetic Finally I have to add that unit tests as well as travis-ci integration within that repo would be great 😉 Thanks a lot for your support - much appreciated! |
|
No problem on my side. The current code generates always 64bits zip files, the RFC contains an option to switch between 32/64 bits, but I haven't implemented it. I have only large files >4 GB here, so there was no reason to enhance the code. |
|
I added a new pull request base on current master: #6893. |
|
I have installed latest owncloud today, and get following error with zipstreamer... PHP Parse error: syntax error, unexpected '[', expecting ')' in /var/www/owncloud/3rdparty/mcnetic/phpzipstreamer/ZipStreamer.php on line 260, any idea? maybe some wrong privilege? |
|
@Povezi please open a new issue here - looks like ZipStreamer required php 5.4 and you are obviously running php5.3 |
|
yap, I am using PHP 5.3.3-7+squeeze19 with Suhosin-Patch (cli) (built: Feb 18 2014 13:59:15) |
|
I raised an issue upstream: McNetic/PHPZipStreamer#7 @Povezi Would still be good to have an issue here as a reminder to update from upstream. |
|
I fixed the issue in ZipStreamer. |
|
@McNetic thanks a lot! I'll update our referenced code these days - THX |
|
@DeepDiver1975 Please can you notify me here when to update owncloud with latest? |
|
Thank you very much! Now new owncloud is working on my php5.3! |
|
I have found out that there is a new problem related to PhpZipStream... if you select multiple files and want them do zip&download, PhpZipStream makes an archive and browser downloads it successfully. But whan I try to uncompress in totalcommander I get an error "please insert disk number 0" and all files are 0 file size... in windows explorer zip can be uncompressed... so I suppose that some flag for multiarchive is set wrongly... |
|
@Povezi please raise zipstreamer issues in the zipstreamer project: https://github.com/McNetic/PHPZipStreamer/ |
|
yap, sorry ;) |
|
This looks like it was fixed in upstream almost as soon as it was reported: McNetic/PHPZipStreamer@0af57cc but the upstream fix is different from the one OC is carrying? It'd be best to stay synced with upstream, I think. |
This commit mainly adds the ability for owncloud to use ZipStreamer instead of the builtin ZipArchive. This reduces disk i/o greatly, as the current implementation creates one temp file for each file to be added to the zip, and then again a temp file of the complete zip, before starting to send the temp zip to the client.
The ZipStreamer creates the zip file on the fly in memory and directly sends the data to the client, no temp file needed at all. The ZipStreamer class was added in a second pull request to 3rdparty.