Skip to content

Commit f8cf215

Browse files
committed
Merge remote-tracking branch 'remotes/esp8266/master'
2 parents a276e81 + 39f36d4 commit f8cf215

File tree

4 files changed

+46
-3
lines changed

4 files changed

+46
-3
lines changed

cores/esp8266/FS.h

+3-1
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,9 @@ class File : public Stream
5959
int read() override;
6060
int peek() override;
6161
void flush() override;
62-
62+
size_t readBytes(char *buffer, size_t length) override {
63+
return read((uint8_t*)buffer, length);
64+
}
6365
size_t read(uint8_t* buf, size_t size);
6466
bool seek(uint32_t pos, SeekMode mode);
6567
size_t position() const;

cores/esp8266/MD5Builder.cpp

+40
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,46 @@ void MD5Builder::addHexString(const char * data){
2323
free(tmp);
2424
}
2525

26+
bool MD5Builder::addStream(Stream & stream, const size_t total_len) {
27+
const int buf_size = 512;
28+
int bytesleft = total_len;
29+
uint8_t * buf = (uint8_t*) malloc(buf_size);
30+
if(buf) {
31+
while((stream.available() > -1) && (bytesleft > 0)) {
32+
33+
// get available data size
34+
int sizeAvailable = stream.available();
35+
if(sizeAvailable) {
36+
int readBytes = sizeAvailable;
37+
38+
// read only the asked bytes
39+
if(readBytes > bytesleft) {
40+
readBytes = bytesleft ;
41+
}
42+
43+
// not read more the buffer can handle
44+
if(readBytes > buf_size) {
45+
readBytes = buf_size;
46+
}
47+
48+
// read data
49+
int bytesread = stream.readBytes(buf, readBytes);
50+
bytesleft -= bytesread;
51+
if(bytesread > 0) {
52+
MD5Update(&_ctx, buf, bytesread);
53+
}
54+
}
55+
// time for network streams
56+
delay(0);
57+
}
58+
// not free null ptr
59+
free(buf);
60+
return (bytesleft == 0);
61+
} else {
62+
return false;
63+
}
64+
}
65+
2666
void MD5Builder::calculate(void){
2767
MD5Final(_buf, &_ctx);
2868
}

cores/esp8266/MD5Builder.h

+1
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ class MD5Builder {
3737
void addHexString(const char * data);
3838
void addHexString(char * data){ addHexString((const char*)data); }
3939
void addHexString(String data){ addHexString(data.c_str()); }
40+
bool addStream(Stream & stream, const size_t total_len);
4041
void calculate(void);
4142
void getBytes(uint8_t * output);
4243
void getChars(char * output);

cores/esp8266/Stream.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -87,8 +87,8 @@ class Stream: public Print {
8787

8888
float parseFloat(); // float version of parseInt
8989

90-
size_t readBytes(char *buffer, size_t length); // read chars from stream into buffer
91-
size_t readBytes(uint8_t *buffer, size_t length) {
90+
virtual size_t readBytes(char *buffer, size_t length); // read chars from stream into buffer
91+
virtual size_t readBytes(uint8_t *buffer, size_t length) {
9292
return readBytes((char *) buffer, length);
9393
}
9494
// terminates if length characters have been read or timeout (see setTimeout)

0 commit comments

Comments
 (0)