@@ -556,6 +556,9 @@ void M5Display::drawPngUrl(const char *url, uint16_t x, uint16_t y,
556
556
return ;
557
557
}
558
558
559
+ // get lenght of document (is -1 when Server sends no Content-Length header)
560
+ int len = http.getSize ();
561
+
559
562
WiFiClient *stream = http.getStreamPtr ();
560
563
561
564
pngle_t *pngle = pngle_new ();
@@ -586,21 +589,25 @@ void M5Display::drawPngUrl(const char *url, uint16_t x, uint16_t y,
586
589
// Feed data to pngle
587
590
uint8_t buf[1024 ];
588
591
int remain = 0 ;
589
- int len ;
590
- while (http.connected ()) {
592
+ int c ;
593
+ while (http.connected () && (len > 0 || len == - 1 ) ) {
591
594
size_t size = stream->available ();
592
595
if (!size) { delay (1 ); continue ; }
593
596
594
597
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 );
597
600
if (fed < 0 ) {
598
601
log_e (" [pngle error] %s" , pngle_error (pngle));
599
602
break ;
600
603
}
601
604
602
- remain = remain + len - fed;
605
+ remain = remain + c - fed;
603
606
if (remain > 0 ) memmove (buf, buf + fed, remain);
607
+
608
+ if (len > 0 ) {
609
+ len -= c;
610
+ }
604
611
}
605
612
}
606
613
0 commit comments