1
0
mirror of https://github.com/esp8266/Arduino.git synced 2025-04-21 10:26:06 +03:00

SD: Implement readBytes (#4931)

This speeds up the ESP8266WebServer::streamFile more than 3 times. Tested on streaming the 800+ Kb file from SD (FAT32), average time without a fix was 9000 ms, with the fix is 2600 ms (maximal possible SPI speed used), which is as fast as streaming the same file from internal SPIFFS. Hardware: WeMos D1 mini.
This commit is contained in:
Konstantin Ryabinin 2018-10-06 01:44:55 +05:00 committed by Earle F. Philhower, III
parent 9c46a81fb6
commit 9bc8ea1b58
2 changed files with 6 additions and 0 deletions

View File

@ -95,6 +95,11 @@ int File::read(void *buf, uint16_t nbyte) {
return 0;
}
size_t File::readBytes(char *buffer, size_t length) {
int result = read(buffer, (uint16_t)length);
return result < 0 ? 0 : (size_t)result;
}
int File::available() {
if (! _file) return 0;

View File

@ -34,6 +34,7 @@ public:
virtual size_t write(uint8_t);
virtual size_t write(const uint8_t *buf, size_t size);
virtual int read();
virtual size_t readBytes(char *buffer, size_t length);
virtual int peek();
virtual int available();
virtual void flush();