From f99e29738946fe3f4c32b01eebd676bd87f3a24b Mon Sep 17 00:00:00 2001 From: Paul Sokolovsky Date: Fri, 5 Aug 2016 02:19:13 +0300 Subject: [PATCH] tinflate.c: Allow to read source in stream mode using d->readSource(). --- src/tinf.h | 4 ++++ src/tinflate.c | 7 +++++-- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/src/tinf.h b/src/tinf.h index 6d27611..e00f171 100644 --- a/src/tinf.h +++ b/src/tinf.h @@ -43,6 +43,10 @@ typedef struct { struct TINF_DATA; typedef struct TINF_DATA { const unsigned char *source; + /* If source above is NULL, this function will be used to read + next byte from source stream */ + unsigned char (*readSource)(struct TINF_DATA *data); + unsigned int tag; unsigned int bitcount; diff --git a/src/tinflate.c b/src/tinflate.c index 5e38f66..a6f6e66 100644 --- a/src/tinflate.c +++ b/src/tinflate.c @@ -166,9 +166,12 @@ static void tinf_build_tree(TINF_TREE *t, const unsigned char *lengths, unsigned * -- decode functions -- * * ---------------------- */ -static unsigned char tinf_read_src_byte(TINF_DATA *d) +unsigned char tinf_read_src_byte(TINF_DATA *d) { - return *d->source++; + if (d->source) { + return *d->source++; + } + return d->readSource(d); } /* get one bit from source stream */