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

Implement lazy open stream #121

Closed
nozavroni opened this issue Sep 18, 2016 · 3 comments
Closed

Implement lazy open stream #121

nozavroni opened this issue Sep 18, 2016 · 3 comments

Comments

@nozavroni
Copy link
Owner

Implement a lazy open stream class (or maybe just make it the default). What this means is that the stream resource isn't opened until an I/O operation is performed on it.

$stream = IO\LazyOpenStream('file:///var/www/data/reports.csv', 'r+b');
echo $stream->getResource(); // null
$stream->read(100);
echo $stream->getResource(); // stream resource 
@nozavroni
Copy link
Owner Author

nozavroni commented Sep 18, 2016

I came up with an alternative solution for this... instead of creating an entirely new stream class, I abstracted the concept of a "stream resource" into a class of its own. the Stream class will now use it internally in place of simply using a php stream resource handle. Then the resource object will lazy-open instead of the stream. Let me demonstrate:

$res = (new CSVelte\IO\Resource('./data/products.csv'))
    ->setBaseMode('w')
    ->setIsPlus(true)
    ->setIsBinary(true);
echo $res->isConnected(); // false 
$stream = Stream::open($res);
$stream->getResource()->isConnected(); // false
$stream->write('helloworld');
echo $stream->getResource()->isConnected(); true

@nozavroni
Copy link
Owner Author

Finished with the exception of documentation

@nozavroni
Copy link
Owner Author

Closing all issues that only need documentation.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
v0.2.x - Streams
documentation
Development

No branches or pull requests

1 participant