Skip to content

Commit

Permalink
add template methods for stream to stream writes to SD and FS
Browse files Browse the repository at this point in the history
  • Loading branch information
ficeto authored and ficeto committed May 14, 2015
1 parent 1ff1914 commit 4ef84f6
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 0 deletions.
22 changes: 22 additions & 0 deletions hardware/esp8266com/esp8266/cores/esp8266/FileSystem.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,28 @@ class FSFile : public Stream {
operator bool(){ return _file > 0; }
char * name();
boolean isDirectory(void);

template<typename T> size_t write(T &src){
uint8_t obuf[64];
size_t doneLen = 0;
size_t sentLen;
int i;

while (src.available() > 64){
src.read(obuf, 64);
sentLen = write(obuf, 64);
doneLen = doneLen + sentLen;
if(sentLen != 64){
return doneLen;
}
}

size_t leftLen = src.available();
src.read(obuf, leftLen);
sentLen = write(obuf, leftLen);
doneLen = doneLen + sentLen;
return doneLen;
}

using Print::write;
};
Expand Down
22 changes: 22 additions & 0 deletions libraries/SD/src/SD.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,28 @@ class File : public Stream {
boolean isDirectory(void);
File openNextFile(uint8_t mode = O_RDONLY);
void rewindDirectory(void);

template<typename T> size_t write(T &src){
uint8_t obuf[512];
size_t doneLen = 0;
size_t sentLen;
int i;

while (src.available() > 512){
src.read(obuf, 512);
sentLen = write(obuf, 512);
doneLen = doneLen + sentLen;
if(sentLen != 512){
return doneLen;
}
}

size_t leftLen = src.available();
src.read(obuf, leftLen);
sentLen = write(obuf, leftLen);
doneLen = doneLen + sentLen;
return doneLen;
}

using Print::write;
};
Expand Down

0 comments on commit 4ef84f6

Please sign in to comment.