Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] add support to open vfs streams with compress.zlib://vfs://path/to/file.txt #125

Closed
wants to merge 8 commits into from

Conversation

mikey179
Copy link
Member

This adds support to open vfs streams using compress.zlib:// as a prefix as described in #121. However, it involves writing to disk as the vfsStream wrapper must return a file resource on its stream_cast method. I tried using php://memory first, but this resulted in a similar error message. Writing to the real file system kind of defeats the purpose of vfsStream of having no file system interaction at all. However, vfsStream could take care of removing such temporary files on its own (not implemented yet), so for the user there would be no difference at all, even though such operations might be a bit slower.

Update: using php://temp works. This solves the problem of having an interaction with the disk - PHP itself will take care of this in case a certain threshold is reached, so vfsStream doesn't have to take care of this. Additionally, this only applies to large files, but most likely not to the overwhelming majority of file sizes in unit tests.

With the current patch, this example code works:

$root = vfsStream::setup("root");
file_put_contents('compress.zlib://vfs://root/test.nbt', 'barbaz');
// displays string(6) "barbaz"
var_dump(file_get_contents('compress.zlib://vfs://root/test.nbt')); 

@@ -278,6 +278,7 @@ protected function resolvePath($path)
*/
public function stream_open($path, $mode, $options, $opened_path)
{
$this->omode = $mode;
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

seems to be unused

mikey179 added 2 commits December 17, 2015 11:22
The canOpenTwoCompressZlibUrlsAtTheSameTime() test currently fails,
it seems it is not compatible with fopen(). This needs to be
investigated while file_get|put_contents() works but not fopen().
@coveralls
Copy link

coveralls commented Jul 20, 2016

Coverage Status

Coverage decreased (-0.03%) to 94.249% when pulling 116f535 on compress_zlib_support into f4aabeb on master.

@mikey179
Copy link
Member Author

Can't even make this work partially with fopen(), having this with file_put_contents() and file_get_contents() only doesn't make sense.

@mikey179 mikey179 closed this Jul 20, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants