Skip to content

Commit

Permalink
Implement inflateReset() function
Browse files Browse the repository at this point in the history
Signed-off-by: Dmitry Eremin-Solenikov <[email protected]>
  • Loading branch information
lumag committed Dec 18, 2018
1 parent 336fca3 commit ae423e6
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 1 deletion.
26 changes: 26 additions & 0 deletions miniz.c
Original file line number Diff line number Diff line change
Expand Up @@ -397,6 +397,32 @@ int mz_inflateInit(mz_streamp pStream)
return mz_inflateInit2(pStream, MZ_DEFAULT_WINDOW_BITS);
}

int mz_inflateReset(mz_streamp pStream)
{
inflate_state *pDecomp;
if (!pStream)
return MZ_STREAM_ERROR;

pStream->data_type = 0;
pStream->adler = 0;
pStream->msg = NULL;
pStream->total_in = 0;
pStream->total_out = 0;
pStream->reserved = 0;

pDecomp = (inflate_state *)pStream->state;

tinfl_init(&pDecomp->m_decomp);
pDecomp->m_dict_ofs = 0;
pDecomp->m_dict_avail = 0;
pDecomp->m_last_status = TINFL_STATUS_NEEDS_MORE_INPUT;
pDecomp->m_first_call = 1;
pDecomp->m_has_flushed = 0;
/* pDecomp->m_window_bits = window_bits */;

return MZ_OK;
}

int mz_inflate(mz_streamp pStream, int flush)
{
inflate_state *pState;
Expand Down
6 changes: 5 additions & 1 deletion miniz.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
zlib replacement in many apps:
The z_stream struct, optional memory allocation callbacks
deflateInit/deflateInit2/deflate/deflateReset/deflateEnd/deflateBound
inflateInit/inflateInit2/inflate/inflateEnd
inflateInit/inflateInit2/inflate/inflateReset/inflateEnd
compress, compress2, compressBound, uncompress
CRC-32, Adler-32 - Using modern, minimal code size, CPU cache friendly routines.
Supports raw deflate streams or standard zlib streams with adler-32 checking.
Expand Down Expand Up @@ -362,6 +362,9 @@ int mz_inflateInit(mz_streamp pStream);
/* window_bits must be MZ_DEFAULT_WINDOW_BITS (to parse zlib header/footer) or -MZ_DEFAULT_WINDOW_BITS (raw deflate). */
int mz_inflateInit2(mz_streamp pStream, int window_bits);

/* Quickly resets a compressor without having to reallocate anything. Same as calling mz_inflateEnd() followed by mz_inflateInit()/mz_inflateInit2(). */
int mz_inflateReset(mz_streamp pStream);

/* Decompresses the input stream to the output, consuming only as much of the input as needed, and writing as much to the output as possible. */
/* Parameters: */
/* pStream is the stream to read from and write to. You must initialize/update the next_in, avail_in, next_out, and avail_out members. */
Expand Down Expand Up @@ -445,6 +448,7 @@ typedef void *const voidpc;
#define compressBound mz_compressBound
#define inflateInit mz_inflateInit
#define inflateInit2 mz_inflateInit2
#define inflateReset mz_inflateReset
#define inflate mz_inflate
#define inflateEnd mz_inflateEnd
#define uncompress mz_uncompress
Expand Down

0 comments on commit ae423e6

Please sign in to comment.