@@ -556,6 +556,9 @@ void M5Display::drawPngUrl(const char *url, uint16_t x, uint16_t y,
556556 return ;
557557 }
558558
559+ // get lenght of document (is -1 when Server sends no Content-Length header)
560+ int len = http.getSize ();
561+
559562 WiFiClient *stream = http.getStreamPtr ();
560563
561564 pngle_t *pngle = pngle_new ();
@@ -586,21 +589,25 @@ void M5Display::drawPngUrl(const char *url, uint16_t x, uint16_t y,
586589 // Feed data to pngle
587590 uint8_t buf[1024 ];
588591 int remain = 0 ;
589- int len ;
590- while (http.connected ()) {
592+ int c ;
593+ while (http.connected () && (len > 0 || len == - 1 ) ) {
591594 size_t size = stream->available ();
592595 if (!size) { delay (1 ); continue ; }
593596
594597 if (size > sizeof (buf) - remain) size = sizeof (buf) - remain;
595- if ((len = stream->readBytes (buf + remain, size)) > 0 ) {
596- int fed = pngle_feed (pngle, buf, remain + len );
598+ if ((c = stream->readBytes (buf + remain, size)) > 0 ) {
599+ int fed = pngle_feed (pngle, buf, remain + c );
597600 if (fed < 0 ) {
598601 log_e (" [pngle error] %s" , pngle_error (pngle));
599602 break ;
600603 }
601604
602- remain = remain + len - fed;
605+ remain = remain + c - fed;
603606 if (remain > 0 ) memmove (buf, buf + fed, remain);
607+
608+ if (len > 0 ) {
609+ len -= c;
610+ }
604611 }
605612 }
606613
0 commit comments