mirror of
https://github.com/esp8266/Arduino.git
synced 2025-08-08 11:22:40 +03:00
Redoing peek() implementation (SD file class).
Now simply seeking backwards by a character in peek() rather than trying to keep track of the extra character read.
This commit is contained in:
@@ -15,39 +15,29 @@
|
||||
#include <SD.h>
|
||||
|
||||
void File::write(uint8_t val) {
|
||||
SD.c = -1;
|
||||
SD.file.write(val);
|
||||
}
|
||||
|
||||
void File::write(const char *str) {
|
||||
SD.c = -1;
|
||||
SD.file.write(str);
|
||||
}
|
||||
|
||||
void File::write(const uint8_t *buf, size_t size) {
|
||||
SD.c = -1;
|
||||
SD.file.write(buf, size);
|
||||
}
|
||||
|
||||
int File::peek() {
|
||||
if (SD.c != -1) return SD.c;
|
||||
SD.c = SD.file.read();
|
||||
return SD.c;
|
||||
char c = SD.file.read();
|
||||
if (c != -1) SD.file.seekCur(-1);
|
||||
return 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;
|
||||
return size() - position();
|
||||
}
|
||||
|
||||
void File::flush() {
|
||||
@@ -55,12 +45,10 @@ void File::flush() {
|
||||
}
|
||||
|
||||
boolean File::seek(uint32_t pos) {
|
||||
SD.c = -1;
|
||||
return SD.file.seekSet(pos);
|
||||
}
|
||||
|
||||
uint32_t File::position() {
|
||||
if (SD.c != -1) return SD.file.curPosition() - 1;
|
||||
return SD.file.curPosition();
|
||||
}
|
||||
|
||||
|
@@ -300,7 +300,6 @@ boolean callback_openPath(SdFile& parentDir, char *filePathComponent,
|
||||
if (p_SD->fileOpenMode == FILE_WRITE) {
|
||||
p_SD->file.seekSet(p_SD->file.fileSize());
|
||||
}
|
||||
p_SD->c = -1;
|
||||
// TODO: Return file open result?
|
||||
return false;
|
||||
}
|
||||
|
@@ -79,8 +79,6 @@ private:
|
||||
// It shouldn't be set directly--it is set via the parameters to `open`.
|
||||
int fileOpenMode;
|
||||
|
||||
int c;
|
||||
|
||||
friend class File;
|
||||
friend boolean callback_openPath(SdFile&, char *, boolean, void *);
|
||||
};
|
||||
|
Reference in New Issue
Block a user