deflate.c File Reference
`#include "deflate.h"`

Go to the source code of this file.

## Classes

struct | config_s

## Macros

#define | NIL 0
#define | TOO_FAR 4096
#define | RANK(f) (((f) * 2) - ((f) > 4 ? 9 : 0))
#define | UPDATE_HASH(s, h, c) (h = (((h)<<s->hash_shift) ^ (c)) & s->hash_mask)
#define | INSERT_STRING(s, str, match_head)
#define | CLEAR_HASH(s)
#define | HCRC_UPDATE(beg)
#define | check_match(s, start, match, length)
#define | FLUSH_BLOCK_ONLY(s, last)
#define | FLUSH_BLOCK(s, last)
#define | MAX_STORED 65535
#define | MIN(a, b) ((a) > (b) ? (b) : (a))

## Typedefs

typedef block_state compress_func | OF((deflate_state *s, int flush))
typedef struct config_s | config

## Enumerations

enum | block_state { need_more , block_done , finish_started , finish_done }

## Functions

int deflateStateCheck | OF ((z_streamp strm))
void slide_hash | OF ((deflate_state *s))
void putShortMSB | OF ((deflate_state *s, uInt b))
unsigned read_buf | OF ((z_streamp strm, Bytef *buf, unsigned size))
uInt longest_match | OF ((deflate_state *s, IPos cur_match))
void | slide_hash (deflate_state *s)
int ZEXPORT | deflateInit_ (z_streamp strm, int level, const char *version, int stream_size)
int ZEXPORT | deflateInit2_ (z_streamp strm, int level, int method, int windowBits, int memLevel, int strategy, const char *version, int stream_size)
int | deflateStateCheck (z_streamp strm)
int ZEXPORT | deflateSetDictionary (z_streamp strm, const Bytef *dictionary, uInt dictLength)
int ZEXPORT | deflateGetDictionary (z_streamp strm, Bytef *dictionary, uInt *dictLength)
int ZEXPORT | deflateResetKeep (z_streamp strm)
int ZEXPORT | deflateReset (z_streamp strm)
int ZEXPORT | deflateSetHeader (z_streamp strm, gz_headerp head)
int ZEXPORT | deflatePending (z_streamp strm, unsigned *pending, int *bits)
int ZEXPORT | deflatePrime (z_streamp strm, int bits, int value)
int ZEXPORT | deflateParams (z_streamp strm, int level, int strategy)
int ZEXPORT | deflateTune (z_streamp strm, int good_length, int max_lazy, int nice_length, int max_chain)
uLong ZEXPORT | deflateBound (z_streamp strm, uLong sourceLen)
void | putShortMSB (deflate_state *s, uInt b)
void | flush_pending (z_streamp strm)
int ZEXPORT | deflate (z_streamp strm, int flush)
int ZEXPORT | deflateEnd (z_streamp strm)
int ZEXPORT | deflateCopy (z_streamp dest, z_streamp source)
unsigned | read_buf (z_streamp strm, Bytef *buf, unsigned size)
void | lm_init (deflate_state *s)
uInt | longest_match (deflate_state *s, IPos cur_match)
void | fill_window (deflate_state *s)
block_state | deflate_stored (deflate_state *s, int flush)
block_state | deflate_fast (deflate_state *s, int flush)
block_state | deflate_slow (deflate_state *s, int flush)
block_state | deflate_rle (deflate_state *s, int flush)
block_state | deflate_huff (deflate_state *s, int flush)

## Variables

const char | deflate_copyright []
const config | configuration_table [10]

## Macro Definition Documentation

## check_match

#define check_match | ( |  | s,
|  |  | start,
|  |  | match,
|  |  | length
| ) |  |

Definition at line 1469 of file deflate.c.

## CLEAR_HASH

#define CLEAR_HASH | ( |  | s | ) |

Value:
s->head[s->hash_size-1] = NIL; \
zmemzero((Bytef *)s->head, (unsigned)(s->hash_size-1)*sizeof(*s->head));
NIL
#define NIL
Definition: deflate.c:107
Bytef
Byte FAR Bytef
Definition: zconf.h:400

Definition at line 192 of file deflate.c.

## FLUSH_BLOCK

#define FLUSH_BLOCK | ( |  | s,
|  |  | last
| ) |  |

Value:
{ \
FLUSH_BLOCK_ONLY(s, last); \
if (s->strm->avail_out == 0) return (last) ? finish_started : need_more; \
}
finish_started
@ finish_started
Definition: deflate.c:69
need_more
@ need_more
Definition: deflate.c:67

Definition at line 1617 of file deflate.c.

## FLUSH_BLOCK_ONLY

#define FLUSH_BLOCK_ONLY | ( |  | s,
|  |  | last
| ) |  |

Value:
{ \
_tr_flush_block(s, (s->block_start >= 0L ? \
(charf *)&s->window[(unsigned)s->block_start] : \
(charf *)Z_NULL), \
(ulg)((long)s->strstart - s->block_start), \
(last)); \
s->block_start = s->strstart; \
flush_pending(s->strm); \
Tracev((stderr,"[FLUSH]")); \
}
charf
char FAR charf
Definition: zconf.h:402
Z_NULL
#define Z_NULL
Definition: zlib.h:212
ulg
unsigned long ulg
Definition: zutil.h:47

Definition at line 1605 of file deflate.c.

## HCRC_UPDATE

#define HCRC_UPDATE | ( |  | beg | ) |

Value:
do { \
if (s->gzhead->hcrc && s->pending > (beg)) \
strm->adler = crc32(strm->adler, s->pending_buf + (beg), \
s->pending - (beg)); \
} while (0)
crc32
unsigned long ZEXPORT crc32(unsigned long crc, const unsigned char FAR *buf, uInt len)
Definition: crc32.c:237

Definition at line 755 of file deflate.c.

## INSERT_STRING

#define INSERT_STRING | ( |  | s,
|  |  | str,
|  |  | match_head
| ) |  |

Value:
(UPDATE_HASH(s, s->ins_h, s->window[(str) + (MIN_MATCH-1)]), \
match_head = s->prev[(str) & s->w_mask] = s->head[s->ins_h], \
s->head[s->ins_h] = (Pos)(str))
UPDATE_HASH
#define UPDATE_HASH(s, h, c)
Definition: deflate.c:163
Pos
ush Pos
Definition: deflate.h:92
MIN_MATCH
#define MIN_MATCH
Definition: zutil.h:77

Definition at line 182 of file deflate.c.

## MAX_STORED

#define MAX_STORED 65535

Definition at line 1623 of file deflate.c.

## MIN

#define MIN | ( |  | a,
|  |  | b
| ) |  | ((a) > (b) ? (b) : (a))

Definition at line 1626 of file deflate.c.

## NIL

#define NIL 0

Definition at line 107 of file deflate.c.

## RANK

#define RANK | ( |  | f | ) | (((f) * 2) - ((f) > 4 ? 9 : 0))

Definition at line 155 of file deflate.c.

## TOO_FAR

#define TOO_FAR 4096

Definition at line 111 of file deflate.c.

## UPDATE_HASH

#define UPDATE_HASH | ( |  | s,
|  |  | h,
|  |  | c
| ) |  | (h = (((h)<<s->hash_shift) ^ (c)) & s->hash_mask)

Definition at line 163 of file deflate.c.

## Typedef Documentation

## config

typedef struct config_s config

## OF

ZEXTERN uLong ZEXPORT crc32_combine64 OF

Definition at line 73 of file deflate.c.

## Enumeration Type Documentation

## block_state

enum block_state

Enumerator
need_more |
block_done |
finish_started |
finish_done |

Definition at line 66 of file deflate.c.

## Function Documentation

## deflate()

int ZEXPORT deflate | ( | z_streamp | strm,
|  | int | flush
| ) |  |

Definition at line 763 of file deflate.c.

## deflate_fast()

block_state deflate_fast | ( | deflate_state * | s,
|  | int | flush
| ) |  |

Definition at line 1824 of file deflate.c.

## deflate_huff()

block_state deflate_huff | ( | deflate_state * | s,
|  | int | flush
| ) |  |

Definition at line 2130 of file deflate.c.

## deflate_rle()

block_state deflate_rle | ( | deflate_state * | s,
|  | int | flush
| ) |  |

Definition at line 2057 of file deflate.c.

## deflate_slow()

block_state deflate_slow | ( | deflate_state * | s,
|  | int | flush
| ) |  |

Definition at line 1926 of file deflate.c.

## deflate_stored()

block_state deflate_stored | ( | deflate_state * | s,
|  | int | flush
| ) |  |

Definition at line 1643 of file deflate.c.

## deflateBound()

uLong ZEXPORT deflateBound | ( | z_streamp | strm,
|  | uLong | sourceLen
| ) |  |

Definition at line 652 of file deflate.c.

## deflateCopy()

int ZEXPORT deflateCopy | ( | z_streamp | dest,
|  | z_streamp | source
| ) |  |

Definition at line 1102 of file deflate.c.

## deflateEnd()

int ZEXPORT deflateEnd | ( | z_streamp | strm | ) |

Definition at line 1076 of file deflate.c.

## deflateGetDictionary()

int ZEXPORT deflateGetDictionary | ( | z_streamp | strm,
|  | Bytef * | dictionary,
|  | uInt * | dictLength
| ) |  |

Definition at line 445 of file deflate.c.

## deflateInit2_()

int ZEXPORT deflateInit2_ | ( | z_streamp | strm,
|  | int | level,
|  | int | method,
|  | int | windowBits,
|  | int | memLevel,
|  | int | strategy,
|  | const char * | version,
|  | int | stream_size
| ) |  |

Definition at line 240 of file deflate.c.

## deflateInit_()

int ZEXPORT deflateInit_ | ( | z_streamp | strm,
|  | int | level,
|  | const char * | version,
|  | int | stream_size
| ) |  |

Definition at line 228 of file deflate.c.

## deflateParams()

int ZEXPORT deflateParams | ( | z_streamp | strm,
|  | int | level,
|  | int | strategy
| ) |  |

Definition at line 568 of file deflate.c.

## deflatePending()

int ZEXPORT deflatePending | ( | z_streamp | strm,
|  | unsigned * | pending,
|  | int * | bits
| ) |  |

Definition at line 528 of file deflate.c.

## deflatePrime()

int ZEXPORT deflatePrime | ( | z_streamp | strm,
|  | int | bits,
|  | int | value
| ) |  |

Definition at line 542 of file deflate.c.

## deflateReset()

int ZEXPORT deflateReset | ( | z_streamp | strm | ) |

Definition at line 505 of file deflate.c.

## deflateResetKeep()

int ZEXPORT deflateResetKeep | ( | z_streamp | strm | ) |

Definition at line 467 of file deflate.c.

## deflateSetDictionary()

int ZEXPORT deflateSetDictionary | ( | z_streamp | strm,
|  | const Bytef * | dictionary,
|  | uInt | dictLength
| ) |  |

Definition at line 376 of file deflate.c.

## deflateSetHeader()

int ZEXPORT deflateSetHeader | ( | z_streamp | strm,
|  | gz_headerp | head
| ) |  |

Definition at line 517 of file deflate.c.

## deflateStateCheck()

int deflateStateCheck | ( | z_streamp | strm | ) |

Definition at line 353 of file deflate.c.

## deflateTune()

int ZEXPORT deflateTune | ( | z_streamp | strm,
|  | int | good_length,
|  | int | max_lazy,
|  | int | nice_length,
|  | int | max_chain
| ) |  |

Definition at line 617 of file deflate.c.

## fill_window()

void fill_window | ( | deflate_state * | s | ) |

Definition at line 1482 of file deflate.c.

## flush_pending()

void flush_pending | ( | z_streamp | strm | ) |

Definition at line 730 of file deflate.c.

## lm_init()

void lm_init | ( | deflate_state * | s | ) |

Definition at line 1194 of file deflate.c.

## longest_match()

uInt longest_match | ( | deflate_state * | s,
|  | IPos | cur_match
| ) |  |

Definition at line 1236 of file deflate.c.

## OF() [1/5]

void slide_hash OF | ( | (deflate_state *s) |  | ) |

## OF() [2/5]

uInt longest_match OF | ( | (deflate_state *s, IPos cur_match) |  | ) |

## OF() [3/5]

void putShortMSB OF | ( | (deflate_state *s, uInt b) |  | ) |

## OF() [4/5]

int deflateStateCheck OF | ( | (z_streamp strm) |  | ) |

## OF() [5/5]

unsigned read_buf OF | ( | (z_streamp strm, Bytef *buf, unsigned size) |  | ) |

## putShortMSB()

void putShortMSB | ( | deflate_state * | s,
|  | uInt | b
| ) |  |

Definition at line 716 of file deflate.c.

## read_buf()

unsigned read_buf | ( | z_streamp | strm,
|  | Bytef * | buf,
|  | unsigned | size
| ) |  |

Definition at line 1164 of file deflate.c.

## slide_hash()

void slide_hash | ( | deflate_state * | s | ) |

Definition at line 201 of file deflate.c.

## Variable Documentation

## configuration_table

const config configuration_table[10]

Initial value:
= {
{0, 0, 0, 0, deflate_stored},
{4, 4, 8, 4, deflate_fast},
{4, 5, 16, 8, deflate_fast},
{4, 6, 32, 32, deflate_fast},
{4, 4, 16, 16, deflate_slow},
{8, 16, 32, 32, deflate_slow},
{8, 16, 128, 128, deflate_slow},
{8, 32, 128, 256, deflate_slow},
{32, 128, 258, 1024, deflate_slow},
{32, 258, 258, 4096, deflate_slow}}
deflate_stored
block_state deflate_stored(deflate_state *s, int flush)
Definition: deflate.c:1643
deflate_fast
block_state deflate_fast(deflate_state *s, int flush)
Definition: deflate.c:1824
deflate_slow
block_state deflate_slow(deflate_state *s, int flush)
Definition: deflate.c:1926

Definition at line 134 of file deflate.c.

## deflate_copyright

const char deflate_copyright[]

Initial value:
=
" deflate 1.2.11 Copyright 1995-2017 Jean-loup Gailly and Mark Adler "

Definition at line 54 of file deflate.c.