Skip to content

Commit 548c7a0

Browse files
Jason2866me-no-dev
andauthored
fix(client): Implement readBytes in NetworkClient for faster downloads
Co-authored-by: me-no-dev <[email protected]>
1 parent cefa32a commit 548c7a0

File tree

2 files changed

+12
-0
lines changed

2 files changed

+12
-0
lines changed

Diff for: libraries/Network/src/NetworkClient.cpp

+8
Original file line numberDiff line numberDiff line change
@@ -477,6 +477,14 @@ int NetworkClient::read(uint8_t *buf, size_t size) {
477477
return res;
478478
}
479479

480+
size_t NetworkClient::readBytes(char *buffer, size_t length) {
481+
int r = read((uint8_t*)buffer, length);
482+
if (r < 0) {
483+
return 0;
484+
}
485+
return (size_t)r;
486+
}
487+
480488
int NetworkClient::peek() {
481489
int res = -1;
482490
if (fd() >= 0 && _rxBuffer) {

Diff for: libraries/Network/src/NetworkClient.h

+4
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,10 @@ class NetworkClient : public ESPLwIPClient {
5959
int available();
6060
int read();
6161
int read(uint8_t *buf, size_t size);
62+
size_t readBytes(char *buffer, size_t length);
63+
size_t readBytes(uint8_t *buffer, size_t length) {
64+
return readBytes((char *)buffer, length);
65+
}
6266
int peek();
6367
void flush();
6468
void stop();

0 commit comments

Comments
 (0)