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:
@ -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();
|
||||
}
|
||||
|
Reference in New Issue
Block a user