ZLIB
Loading...
Searching...
No Matches
infback.c File Reference

Inflate using a call-back interface. More...

#include "zutil.h"
#include "inftrees.h"
#include "inflate.h"
#include "inffast.h"
#include "inffixed.h"

Macros

#define LOAD()
 Load returned state from inflate_fast()
 
#define RESTORE()
 Set state from registers for inflate_fast()
 
#define INITBITS()
 Clear the input bit accumulator.
 
#define PULL()
 Assure that some input is available.
 
#define PULLBYTE()
 Get a byte of input into the bit accumulator, or return from inflateBack() with an error if there is no input available.
 
#define NEEDBITS(n)
 Assure that there are at least n bits in the bit accumulator.
 
#define BITS(n)    ((unsigned)hold & ((1U << (n)) - 1))
 Return the low n bits of the bit accumulator (n < 16)
 
#define DROPBITS(n)
 Remove n bits from the bit accumulator.
 
#define BYTEBITS()
 Remove zero to seven bits as needed to go to a byte boundary.
 
#define ROOM()
 Assure that some output space is available, by writing out the window if it's full.
 

Functions

int ZEXPORT inflateBackInit_ (z_streamp strm, int windowBits, unsigned char *window, const char *version, int stream_size)
 Initialize the internal stream state for decompression using inflateBack() calls.
 
int ZEXPORT inflateBack (z_streamp strm, in_func in, void *in_desc, out_func out, void *out_desc)
 Does a raw inflate with a single call using a call-back interface for input and output.
 
int ZEXPORT inflateBackEnd (z_streamp strm)
 All memory allocated by inflateBackInit() is freed.
 

Detailed Description

Inflate using a call-back interface.

Copyright (C) 1995-2022 Mark Adler For conditions of distribution and use, see copyright notice in zlib.h

This code is largely copied from inflate.c. Normally either infback.o or inflate.o would be linked into an application–not both. The interface with inffast.c is retained so that optimized assembler-coded versions of inflate_fast() can be used with either inflate.c or infback.c.

Macro Definition Documentation

◆ BYTEBITS

#define BYTEBITS ( )
Value:
do { \
hold >>= bits & 7; \
bits -= bits & 7; \
} while (0)

Remove zero to seven bits as needed to go to a byte boundary.

◆ DROPBITS

#define DROPBITS (   n)
Value:
do { \
hold >>= (n); \
bits -= (unsigned)(n); \
} while (0)

Remove n bits from the bit accumulator.

◆ INITBITS

#define INITBITS ( )
Value:
do { \
hold = 0; \
bits = 0; \
} while (0)

Clear the input bit accumulator.

◆ LOAD

#define LOAD ( )
Value:
do { \
put = strm->next_out; \
left = strm->avail_out; \
next = strm->next_in; \
have = strm->avail_in; \
hold = state->hold; \
bits = state->bits; \
} while (0)

Load returned state from inflate_fast()

◆ NEEDBITS

#define NEEDBITS (   n)
Value:
do { \
while (bits < (unsigned)(n)) \
PULLBYTE(); \
} while (0)

Assure that there are at least n bits in the bit accumulator.

If there is not enough available input to do that, then return from inflateBack() with an error.

◆ PULL

#define PULL ( )
Value:
do { \
if (have == 0) { \
have = in(in_desc, &next); \
if (have == 0) { \
next = Z_NULL; \
ret = Z_BUF_ERROR; \
goto inf_leave; \
} \
} \
} while (0)
#define Z_BUF_ERROR
Buffer full error.
Definition zlib.h:212
#define Z_NULL
for initializing zalloc, zfree, opaque
Definition zlib.h:245

Assure that some input is available.

If input is requested, but denied, then return a Z_BUF_ERROR from inflateBack().

◆ PULLBYTE

#define PULLBYTE ( )
Value:
do { \
PULL(); \
have--; \
hold += (unsigned long)(*next++) << bits; \
bits += 8; \
} while (0)

Get a byte of input into the bit accumulator, or return from inflateBack() with an error if there is no input available.

◆ RESTORE

#define RESTORE ( )
Value:
do { \
strm->next_out = put; \
strm->avail_out = left; \
strm->next_in = next; \
strm->avail_in = have; \
state->hold = hold; \
state->bits = bits; \
} while (0)

Set state from registers for inflate_fast()

◆ ROOM

#define ROOM ( )
Value:
do { \
if (left == 0) { \
put = state->window; \
left = state->wsize; \
state->whave = left; \
if (out(out_desc, put, left)) { \
ret = Z_BUF_ERROR; \
goto inf_leave; \
} \
} \
} while (0)

Assure that some output space is available, by writing out the window if it's full.

If the write fails, return from inflateBack() with a Z_BUF_ERROR.

Function Documentation

◆ inflateBackInit_()

int ZEXPORT inflateBackInit_ ( z_streamp  strm,
int  windowBits,
unsigned char *  window,
const char *  version,
int  stream_size 
)

Initialize the internal stream state for decompression using inflateBack() calls.

The fields zalloc, zfree and opaque in strm must be initialized before the call. If zalloc and zfree are Z_NULL, then the default library- derived memory allocation routines are used. windowBits is the base two logarithm of the window size, in the range 8..15. window is a caller supplied buffer of that size. Except for special applications where it is assured that deflate was used with small window sizes, windowBits must be 15 and a 32K byte window must be supplied to be able to decompress general deflate streams.

See inflateBack() for the usage of these routines.

Returns
Z_OK on success
Z_STREAM_ERROR if any of the parameters are invalid
Z_MEM_ERROR if the internal state could not be allocated
Z_VERSION_ERROR if the version of the library does not match the version of the header file.