diff options
-rw-r--r-- | ports/stm32/mboot/gzstream.c | 16 |
1 files changed, 11 insertions, 5 deletions
diff --git a/ports/stm32/mboot/gzstream.c b/ports/stm32/mboot/gzstream.c index 20ba33045..4f8a4a40c 100644 --- a/ports/stm32/mboot/gzstream.c +++ b/ports/stm32/mboot/gzstream.c @@ -38,7 +38,7 @@ typedef struct _gz_stream_t { void *stream_data; stream_read_t stream_read; - TINF_DATA tinf; + struct uzlib_uncomp tinf; uint8_t buf[512]; uint8_t dict[DICT_SIZE]; } gz_stream_t; @@ -66,7 +66,7 @@ int gz_stream_init(void *stream_data, stream_read_t stream_read) { gz_stream.stream_read = stream_read; memset(&gz_stream.tinf, 0, sizeof(gz_stream.tinf)); - gz_stream.tinf.readSource = gz_stream_read_src; + gz_stream.tinf.source_read_cb = gz_stream_read_src; int st = uzlib_gzip_parse_header(&gz_stream.tinf); if (st != TINF_OK) { @@ -79,15 +79,21 @@ int gz_stream_init(void *stream_data, stream_read_t stream_read) { } int gz_stream_read(size_t len, uint8_t *buf) { + if (gz_stream.tinf.source == NULL && gz_stream.tinf.source_read_cb == NULL) { + // End of stream. + return 0; + } gz_stream.tinf.dest = buf; gz_stream.tinf.dest_limit = buf + len; int st = uzlib_uncompress_chksum(&gz_stream.tinf); - if (st == TINF_DONE) { - return 0; - } if (st < 0) { return st; } + if (st == TINF_DONE) { + // Indicate end-of-stream for subsequent calls. + gz_stream.tinf.source = NULL; + gz_stream.tinf.source_read_cb = NULL; + } return gz_stream.tinf.dest - buf; } |