File tree 4 files changed +46
-3
lines changed
4 files changed +46
-3
lines changed Original file line number Diff line number Diff line change @@ -59,7 +59,9 @@ class File : public Stream
59
59
int read () override ;
60
60
int peek () override ;
61
61
void flush () override ;
62
-
62
+ size_t readBytes (char *buffer, size_t length) override {
63
+ return read ((uint8_t *)buffer, length);
64
+ }
63
65
size_t read (uint8_t * buf, size_t size);
64
66
bool seek (uint32_t pos, SeekMode mode);
65
67
size_t position () const ;
Original file line number Diff line number Diff line change @@ -23,6 +23,46 @@ void MD5Builder::addHexString(const char * data){
23
23
free (tmp);
24
24
}
25
25
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
+
26
66
void MD5Builder::calculate (void ){
27
67
MD5Final (_buf, &_ctx);
28
68
}
Original file line number Diff line number Diff line change @@ -37,6 +37,7 @@ class MD5Builder {
37
37
void addHexString (const char * data);
38
38
void addHexString (char * data){ addHexString ((const char *)data); }
39
39
void addHexString (String data){ addHexString (data.c_str ()); }
40
+ bool addStream (Stream & stream, const size_t total_len);
40
41
void calculate (void );
41
42
void getBytes (uint8_t * output);
42
43
void getChars (char * output);
Original file line number Diff line number Diff line change @@ -87,8 +87,8 @@ class Stream: public Print {
87
87
88
88
float parseFloat (); // float version of parseInt
89
89
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) {
92
92
return readBytes ((char *) buffer, length);
93
93
}
94
94
// terminates if length characters have been read or timeout (see setTimeout)
You can’t perform that action at this time.
0 commit comments