Skip to content

Commit

Permalink
enable progress_cb when source=buffer
Browse files Browse the repository at this point in the history
  • Loading branch information
tobozo committed Jan 11, 2025
1 parent 2f2d263 commit 7d48cf5
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
9 changes: 9 additions & 0 deletions src/uzlib/genlz77.c
Original file line number Diff line number Diff line change
Expand Up @@ -76,10 +76,16 @@ static inline void copy(void *data, unsigned offset, unsigned len)
}


// used only when uzlib_compress is in buffer mode (when in stream mode, progress_cb is managed from outside)
#define UZLIB_PROGRESS(b,t) if( data->is_stream == 0 && data->progress_cb ) data->progress_cb(b, t);

void uzlib_compress(struct uzlib_comp *data, const uint8_t *src, unsigned slen)
{
UZLIB_PROGRESS(0,slen);

const uint8_t *top = src + slen - MIN_MATCH;
while (src < top) {
UZLIB_PROGRESS( slen-(top-src), slen);
int h = HASH(data, src);
const uint8_t **bucket = &data->hash_table[h & (HASH_SIZE - 1)];
const uint8_t *subs = *bucket;
Expand All @@ -102,6 +108,7 @@ void uzlib_compress(struct uzlib_comp *data, const uint8_t *src, unsigned slen)
while (src < top) {
literal(data, *src++);
}
UZLIB_PROGRESS( slen, slen);
}


Expand Down Expand Up @@ -138,6 +145,8 @@ int uzlib_deflate_init_stream(struct uzlib_comp* ctx, uzlib_stream* uzstream){
break;
}

ctx->is_stream = 1; // progress_cb is triggered from outside

uzstream->ctx = ctx;

if( ctx->progress_cb )
Expand Down
7 changes: 4 additions & 3 deletions src/uzlib/uzlib.h
Original file line number Diff line number Diff line change
Expand Up @@ -189,9 +189,10 @@ struct uzlib_comp {
// output stream byte writer
unsigned int (*writeDestByte)(struct uzlib_comp *data, unsigned char byte);

char checksum_type;
char grow_buffer;
unsigned char reserved[2];
char checksum_type; // crc32 or adler32
char grow_buffer; // 1 = enables realloc() in outbits() and out4bytes() functions
char is_stream; // 1 = disables calling progress_cb() from uzlib_compress()
unsigned char reserved[1];

};

Expand Down

0 comments on commit 7d48cf5

Please sign in to comment.