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

Add a MultiInstanceFile to allow many file handles to the same resource #220

Merged
merged 2 commits into from
Feb 24, 2020
Merged

Add a MultiInstanceFile to allow many file handles to the same resource #220

merged 2 commits into from
Feb 24, 2020

Conversation

bizurkur
Copy link
Contributor

This should allow any number of handles to be opened to the same vfs resource, but each maintain separate pointers to the place in the file they are.

  • Handle A should know it's at position X
  • Handle B should know it's at position Y
  • Each file handle should not interfere with the other file handle's position when performing operations

In other words, this is now possible (how it works with normal files):

$root = vfsStream::setup();
$file = vfsStream::newFile('foo')->setContent('baz2')->at($root);

$fp1 = fopen($file, 'rb');
$fp2 = fopen($file, 'rb');

$this->assertEquals('baz2', fread($fp1, 4096));

// previously this would be a blank string, as fp1 read all the data
$this->assertEquals('baz2', fread($fp2, 4096)); 

fclose($fp1);
fclose($fp2);

Closes #129

@bizurkur bizurkur requested a review from a team February 20, 2020 23:24
Copy link
Member

@mikey179 mikey179 left a comment

Choose a reason for hiding this comment

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

Overall I'm not against this, as this solves a bug in the library and doesn't introduce anything that clutters the public API. My only gripe with it right now is the name MultiInstanceFile.

Having said that, for me it's another piece in the puzzle of how things could be restructured internally. I can't put them all together in my mind quite yet, but my idea for improving the class names in #213 is part of that. Especially the implementation of restorePosition() and savePosition() show that there's massive room for improvement and that maybe not all informations are at the place where they ought to be.

src/MultiInstanceFile.php Outdated Show resolved Hide resolved
@bizurkur bizurkur requested a review from mikey179 February 22, 2020 16:04
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.

Multiple fopen on same file share the same pointer
3 participants