-
Notifications
You must be signed in to change notification settings - Fork 7.6k
Implements seekDir and getNextFileName on FS Lib to improve performance #7229
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
Conversation
361cfb4
to
1a9c389
Compare
For |
Tested using this sketch confirming that the new function is way much faster: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Apart from the requested changes looks good.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Now its return String name directly or String empty
The speed improvement is amazing! For a webserver SD filexplorer the time for listing is currently about 2 seconds (very blocking), with this PR only 20 msecs (hundreds of mp3 files on SD card). Works fine here! But for the Javascript based file explorer tree i also need the information wether it's a file or directory. Is there a way to get it? ` String VFSFileImpl::getNextFileName() ` Thank's! |
I made a speedtest example for PIO here https://github.com/tueddy/FS/tree/main/example Samsung Evo 32GB: Kingston 8GB, a bit older card: Transcend 16GB: Scandisk 16GB: |
@SuGlider waiting on your approval here :) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
a small hint for String's
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Lucasczm - Thanks for the PR! Very good.
@Lucasczm - I can't rebase it from here. Please do it in your end in order to be able to merge it. Thanks. |
@SuGlider updated! |
Can't test it just at the moment, but can I distinguish whether in the listing is a file or directory with this commit? Thank's for your work! |
@tueddy The seekDir() implementation will only be useful if the other functions are available in FS and VFS too, see @Lucasczm How do you use seekDir() without the other functions? |
getNextFileName() works fine in 2.0.6, but how can i detect now if return value is a file or directory? |
if (file->d_type != DT_REG && file->d_type != DT_DIR) { | ||
return ""; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This behaviour is inconsistent with openNextFile()
which skips to the next file.
It's not possible to tell the difference between "end of file list" and "something that is not a file or directory".
String fname = String(file->d_name); | ||
String name = String(_path); | ||
if (!fname.startsWith("/") && !name.endsWith("/")) { | ||
name += "/"; | ||
} | ||
name += fname; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is the "path", not the "name" of the file.
This results in more effort by users of this function to remove the directory name (which they already have) from every filename.
(The openNextFile()
function returns a File
so it's possible to use name()
or path()
)
Description of Change
Implemented two functions:
Examples:
Tests scenarios
Tested on PlatformIO and Arduino core v2.0.4 with ESP32 LILYGO PoE Board
Related links
#5002