1
0
mirror of https://github.com/esp8266/Arduino.git synced 2025-06-16 11:21:18 +03:00

SD File object implements Stream.

Added peak() and available() using a single byte buffer.
Added flush().
This commit is contained in:
David A. Mellis
2010-11-20 11:45:05 -05:00
parent 6788eea3b8
commit fcc4188b15
4 changed files with 39 additions and 12 deletions

View File

@ -26,10 +26,31 @@ void File::write(const uint8_t *buf, size_t size) {
SD.file.write(buf, size);
}
int File::peek() {
if (SD.c != -1) return SD.c;
SD.c = SD.file.read();
return SD.c;
}
int File::read() {
if (SD.c != -1) {
int tmp = SD.c;
SD.c = -1;
return tmp;
}
return SD.file.read();
}
int File::available() {
if (SD.c != -1) return 1;
SD.c = SD.file.read();
return SD.c != -1;
}
void File::flush() {
SD.file.sync();
}
void File::close() {
SD.file.close();
}