Skip to content

Commit 670e40e

Browse files
committed
add fileSize() method to Dir object
1 parent fe0bc0f commit 670e40e

File tree

4 files changed

+17
-0
lines changed

4 files changed

+17
-0
lines changed

hardware/esp8266com/esp8266/cores/esp8266/FS.cpp

+8
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,14 @@ String Dir::fileName() {
144144
return _impl->fileName();
145145
}
146146

147+
size_t Dir::fileSize() {
148+
if (!_impl) {
149+
return 0;
150+
}
151+
152+
return _impl->fileSize();
153+
}
154+
147155
bool Dir::next() {
148156
if (!_impl) {
149157
return false;

hardware/esp8266com/esp8266/cores/esp8266/FS.h

+1
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ class Dir {
7878

7979
File openFile(const char* mode);
8080
String fileName();
81+
size_t fileSize();
8182
bool next();
8283

8384
protected:

hardware/esp8266com/esp8266/cores/esp8266/FSImpl.h

+1
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ class DirImpl {
5656
virtual ~DirImpl() { }
5757
virtual FileImplPtr openFile(OpenMode openMode, AccessMode accessMode) = 0;
5858
virtual const char* fileName() = 0;
59+
virtual size_t fileSize() = 0;
5960
virtual bool next() = 0;
6061
};
6162

hardware/esp8266com/esp8266/cores/esp8266/spiffs_api.cpp

+7
Original file line numberDiff line numberDiff line change
@@ -308,6 +308,13 @@ class SPIFFSDirImpl : public DirImpl {
308308
return (const char*) _dirent.name;
309309
}
310310

311+
size_t fileSize() override {
312+
if (!_valid)
313+
return 0;
314+
315+
return _dirent.size;
316+
}
317+
311318
bool next() override {
312319
spiffs_dirent* result = SPIFFS_readdir(&_dir, &_dirent);
313320
_valid = (result != nullptr);

0 commit comments

Comments
 (0)