Skip to content

Commit 163a983

Browse files
ficetoficeto
authored andcommitted
Revert "Edit SD Server example to use the new Write(Stream) method"
This reverts commit 4ae8a6d.
1 parent 4ae8a6d commit 163a983

File tree

1 file changed

+15
-2
lines changed
  • hardware/esp8266com/esp8266/libraries/ESP8266WebServer/examples/SDWebServer

1 file changed

+15
-2
lines changed

hardware/esp8266com/esp8266/libraries/ESP8266WebServer/examples/SDWebServer/SDWebServer.ino

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -111,10 +111,23 @@ bool loadFromSdCard(String path){
111111
dataType = 0;
112112
path = 0;
113113

114-
if(client.write(dataFile) != dataFile.size()){
114+
uint8_t obuf[WWW_BUF_SIZE];
115+
116+
while (dataFile.available() > WWW_BUF_SIZE){
117+
dataFile.read(obuf, WWW_BUF_SIZE);
118+
if(client.write(obuf, WWW_BUF_SIZE) != WWW_BUF_SIZE){
119+
DBG_OUTPUT_PORT.println("Sent less data than expected!");
120+
dataFile.close();
121+
return true;
122+
}
123+
}
124+
uint16_t leftLen = dataFile.available();
125+
dataFile.read(obuf, leftLen);
126+
if(client.write(obuf, leftLen) != leftLen){
115127
DBG_OUTPUT_PORT.println("Sent less data than expected!");
128+
dataFile.close();
129+
return true;
116130
}
117-
118131
dataFile.close();
119132
client.stop();
120133
return true;

0 commit comments

Comments
 (0)