You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
What are your plans for the API, do you have anything in mind?
I agree that the API surface is much more complex than everything I've ever needed for my (perhaps somewhat simple) use cases. I would welcome to have something like read(string $path): PromiseInterface<string> and readStream(string $path): ReadableStreamInterface<string> more prominently instead of exposing low-level file and directory objects.
I should have work this issue out better as this is really about streaming the contents of a directory. @CharlotteDunois is already working on improving the reading and writing to and from files.
To simplify that API I'd like to collapse both into read(string $path): Observable using RxPHP. To clarify the read() method is for use cases where you only get a small set of results where readStream() is to be used when the call will yield a lot of results and will cause increased memory usage. Now when using observables we can easily do both.
$filesystem->read(__DIR__)->subscribe(function (NodeInterface$node) {
// Do something with $node
});
Using observables we can filter out files, directories, or symlinks:
$filesystem->read(__DIR__)->filter(function (NodeInterface$node) {
// Filter out everything by filesreturn$nodeinstanceof FileInterface;
})->subscribe(function (NodeInterface$node) {
// Do something with $node
});
Or to go even more advanced filter our all files above 1KB:
$filesystem->read(__DIR__)->filter(function (NodeInterface$node) {
return$nodeinstanceof FileInterface;
})->filter(function (FileInterface$file) {
// This example is actually more complicated because we have to deal with a promise but this is the basic ideareturn$file->size() < 1024;
})->subscribe(function (FileInterface$file) {
// Do something with $file
});
Activity
clue commentedon Oct 28, 2018
What are your plans for the API, do you have anything in mind?
I agree that the API surface is much more complex than everything I've ever needed for my (perhaps somewhat simple) use cases. I would welcome to have something like
read(string $path): PromiseInterface<string>andreadStream(string $path): ReadableStreamInterface<string>more prominently instead of exposing low-level file and directory objects.WyriHaximus commentedon Oct 28, 2018
I should have work this issue out better as this is really about streaming the contents of a directory. @CharlotteDunois is already working on improving the reading and writing to and from files.
To simplify that API I'd like to collapse both into
read(string $path): ObservableusingRxPHP. To clarify theread()method is for use cases where you only get a small set of results wherereadStream()is to be used when the call will yield a lot of results and will cause increased memory usage. Now when using observables we can easily do both.For small loads:
For large loads:
Using observables we can filter out files, directories, or symlinks:
Or to go even more advanced filter our all files above 1KB:
WyriHaximus commentedon Nov 13, 2018
@CharlotteDunois sorry for the late response, but go for it, this makes a lot of sense 👍