Lines Matching +full:zlib +full:- +full:level
3 /* zlib-ng.h -- interface of the 'zlib-ng' compression library, forked from zlib.
5 Copyright (C) 1995-2016 Jean-loup Gailly and Mark Adler
7 This software is provided 'as-is', without any express or implied
23 Jean-loup Gailly Mark Adler
27 The data format used by the zlib library is described by RFCs (Request for
29 (zlib format), rfc1951 (deflate format) and rfc1952 (gzip format).
33 # error Include zlib-ng.h for zlib-ng API or zlib.h for zlib-compat API but not both
37 #include "zconf-ng.h"
42 # error Missing zconf-ng.h add binary output directory to include directories
55 #define ZLIBNG_VER_STATUS 0 /* 0=devel, 1-E=beta, F=Release */
56 #define ZLIBNG_VER_MODIFIED 0 /* non-zero if modified externally from zlib-ng */
59 The 'zlib' compression library provides in-memory compression and
70 The compressed data format used by default by the in-memory functions is
71 the zlib format, which is a zlib wrapper documented in RFC 1950, wrapped
76 with "gz". The gzip format is different from the zlib format. gzip is a
82 The zlib format was designed to be compact and fast for use in memory
83 and on communications channels. The gzip format was designed for single-
84 file compression on file systems, has a larger header than zlib to maintain
85 directory information, and uses a different, slower check method than zlib.
115 uint32_t adler; /* Adler-32 or CRC-32 value of the uncompressed data */
122 gzip header information passed to and from zlib routines. See RFC 1952
133 uint8_t *name; /* pointer to zero-terminated file name or NULL */
135 uint8_t *comment; /* pointer to zero-terminated comment or NULL */
156 If zlib is used in a multi-threaded application, zalloc and zfree must be
157 thread safe. In that case, zlib is thread-safe. When zalloc and zfree are
181 #define Z_ERRNO (-1)
182 #define Z_STREAM_ERROR (-2)
183 #define Z_DATA_ERROR (-3)
184 #define Z_MEM_ERROR (-4)
185 #define Z_BUF_ERROR (-5)
186 #define Z_VERSION_ERROR (-6)
194 #define Z_DEFAULT_COMPRESSION (-1)
213 #define Z_NULL NULL /* for compatibility with zlib, was for initializing zalloc, zfree, opaque */
222 compatible with the zlib-ng.h header file used by the application. This check
228 int zng_deflateInit(zng_stream *strm, int level);
235 The compression level must be Z_DEFAULT_COMPRESSION, or between 0 and 9:
239 equivalent to level 6).
242 memory, Z_STREAM_ERROR if level is not a valid compression level, or
243 Z_VERSION_ERROR if the zlib library version (zng_version) is incompatible
261 - Compress more input starting at next_in and update next_in and avail_in
266 - Generate more output starting at next_out and update next_out and avail_out
322 avail_out), until the flush is complete (deflate returns with non-zero
342 deflate() sets strm->adler to the Adler-32 checksum of all input read
344 strm->adler will be the CRC-32 checksum of the input read so far. (See
347 deflate() may update strm->data_type if it can make a good guess about
392 memory, Z_VERSION_ERROR if the zlib library version is incompatible with the
398 implementation of inflateInit() does not process any header information --
414 - Decompress more input starting at next_in and update next_in and avail_in
420 - Generate more output starting at next_out and update next_out and avail_out
440 the zlib or gzip format, this will cause inflate() to return immediately
446 To assist in this, on return inflate() always sets strm->data_type to the
447 number of unused bits in the last byte taken from strm->next_in, plus 64 if
449 128 if inflate() returned immediately after decoding an end-of-block code or
451 stream. The end-of-block will not be indicated until all of the uncompressed
452 data from that block has been written to strm->next_out. The number of
463 256 is added to the value of strm->data_type when inflate() returns
490 below), inflate sets strm->adler to the Adler-32 checksum of the dictionary
492 strm->adler to the Adler-32 checksum of all output produced so far (that is,
494 below. At the end of the stream, inflate() checks that its computed Adler-32
498 inflate() can decompress and check either zlib-wrapped or gzip-wrapped
502 gzip-wrapped deflate data, strm->adler32 is set to the CRC-32 of the output
503 produced so far. The CRC-32 is checked against the gzip trailer, as is the
510 corrupted (input stream not conforming to the zlib format or incorrect check
511 value, in which case strm->msg points to a string with a more specific
544 int zng_deflateInit2(zng_stream *strm, int level, int method, int windowBits, int memLevel, int…
560 will result in 9 (a 512-byte window). In that case, providing 8 to
561 inflateInit2() will result in an error when the zlib header with 9 is
566 windowBits can also be -8..-15 for raw deflate. In this case, -windowBits
568 with no zlib header or trailer, and will not compute a check value.
572 compressed data instead of a zlib wrapper. The gzip header will have no
576 being written, strm->adler is a CRC-32 instead of an Adler-32.
578 For raw deflate or gzip encoding, a request for a 256-byte window is
579 rejected as invalid, since only the zlib header provides a means of
591 string match), or Z_RLE to limit match distances to one (run-length
605 method), or Z_VERSION_ERROR if the zlib library version (zng_version) is
615 without producing any compressed output. When using the zlib format, this
640 Upon return of this function, strm->adler is set to the Adler-32 value
642 which dictionary has been used by the compressor. (The Adler-32 value
645 Adler-32 value is not computed and strm->adler is not set.
666 to 258 bytes less in that case, due to how zlib's implementation of deflate
668 up to 258 bytes long. If the application needs the last window-size bytes of
669 input, then that would need to be saved by the application outside of zlib.
681 tried, for example when there are several ways of pre-processing the input
698 will leave the compression level and any other attributes that may have been
706 int32_t zng_deflateParams(zng_stream *strm, int32_t level, int32_t strategy);
708 Dynamically update the compression level and compression strategy. The
709 interpretation of level and strategy is as in deflateInit2(). This can be
712 If the compression approach (which is a function of the level) or the
715 compressed with the old level and strategy using deflate(strm, Z_BLOCK).
717 respectively. The new level and strategy will take effect at the next call
729 If this is done, the old level and strategy will be applied to the data
730 compressed before deflateParams(), and the new level and strategy will be
746 used by someone who understands the algorithm used by zlib's deflate for
809 ignored -- the extra flags are set according to the compression level). The
813 the current versions of the command-line version of gzip (up through version
814 1.3.x) do not support header crc's, and will report that it is a "multi-part
843 the zlib header of the compressed stream.
845 windowBits can also be -8..-15 for raw inflate. In this case, -windowBits
847 not looking for a zlib or gzip header, not generating a check value, and not
852 recommended that a check value such as an Adler-32 or a CRC-32 be applied to
853 the uncompressed data as is done in the zlib, gzip, and zip formats. For
854 most applications, the zlib format should be used as is. Note that comments
858 32 to windowBits to enable zlib and gzip decoding with automatic header
859 detection, or add 16 to decode only the gzip format (the zlib format will
860 return a Z_DATA_ERROR). If a gzip stream is being decoded, strm->adler is a
861 CRC-32 instead of an Adler-32. Unlike the gunzip utility and gzread() (see
869 memory, Z_VERSION_ERROR if the zlib library version is incompatible with the
873 apart from possibly reading the zlib header if present: actual decompression
876 of inflateInit2() does not process any header information -- that is
886 can be determined from the Adler-32 value returned by that call of inflate.
897 expected one (incorrect Adler-32 value). inflateSetDictionary does not
1002 return value down 16 bits. If the upper value is -1 and the lower value is
1004 If the upper value is -1 and the lower value is non-zero, then inflate is in
1006 bytes from the input remaining to copy. If the upper value is not -1, then
1022 inflateMark returns the value noted above, or -65536 if the provided
1032 As inflate() processes the gzip stream, head->done is zero until the header
1033 is completed, at which time head->done is set to one. If a zlib stream is
1034 being decoded, then head->done is set to -1 to indicate that there will be
1072 before the call. If zalloc and zfree are NULL, then the default library-
1094 inflateBack() does a raw inflate with a single call using a call-back
1103 and to initialize the state with the user-provided window buffer.
1108 A raw deflate stream is one with no zlib or gzip header or trailer.
1113 behavior of inflate(), which expects a zlib header and trailer around the
1123 there is no input available, in() must return zero -- buf is ignored in that
1124 case -- and inflateBack() will return a buffer error. inflateBack() will
1125 call out(out_desc, buf, len) to write the uncompressed data buf[0..len-1].
1126 out() should return zero on success, or non-zero on failure. If out()
1127 returns non-zero, inflateBack() will return with an error. Neither in() nor
1130 The length written by out() will be at most the window size. Any non-zero
1134 setting strm->next_in and strm->avail_in. If that input is exhausted, then
1135 in() will be called. Therefore strm->next_in must be initialized before
1136 calling inflateBack(). If strm->next_in is NULL, then in() will be called
1137 immediately for input. If strm->next_in is not NULL, then strm->avail_in
1138 must also be initialized, and then if strm->avail_in is not zero, input will
1139 initially be taken from strm->next_in[0 .. strm->avail_in - 1].
1143 descriptors can be optionally used to pass any information that the caller-
1146 On return, inflateBack() will set strm->next_in and strm->avail_in to
1150 in the deflate stream (in which case strm->msg is set to indicate the nature
1153 using strm->next_in which will be NULL only if in() returned an error. If
1154 strm->next_in is not NULL, then the Z_BUF_ERROR was due to out() returning
1155 non-zero. (in() will always be called before out(), so strm->next_in is
1156 assured to be defined if out() returns non-zero.) Note that inflateBack()
1171 /* Return flags indicating compile-time options.
1181 9: ASMV or ASMINF -- use ASM code
1182 10: ZLIB_WINAPI -- exported functions use the WINAPI calling convention
1185 One-time table building (smaller code, but not thread-safe if true):
1186 12: BUILDFIXED -- build static block decoding tables when needed (not supported by zlib-ng)
1187 13: DYNAMIC_CRC_TABLE -- build CRC calculation tables when needed
1191 16: NO_GZCOMPRESS -- gz* functions cannot compress (to avoid linking
1193 17: NO_GZIP -- deflate can't write gzip streams, and inflate can't detect
1195 18-19: 0 (reserved)
1198 20: PKZIP_BUG_WORKAROUND -- slightly more permissive inflate
1199 21: FASTEST -- deflate algorithm with only one, lowest compression level
1203 24: 0 = vs*, 1 = s* -- 1 means limited to 20 arguments after the format
1204 25: 0 = *nprintf, 1 = *printf -- 1 means gzprintf() not secure!
1205 26: 0 = returns value, 1 = void -- 1 means inferred string length returned
1208 27-31: 0 (reserved)
1216 stream-oriented functions. To simplify the interface, some default options
1217 are assumed (compression level and memory usage, standard memory allocation
1229 compressed data. compress() is equivalent to compress2() with a level
1238 …_compress2(uint8_t *dest, size_t *destLen, const uint8_t *source, size_t sourceLen, int32_t level);
1240 Compresses the source buffer into the destination buffer. The level
1249 Z_STREAM_ERROR if the level parameter is invalid.
1294 "gz". The gzip format is different from the zlib format. gzip is a gzip
1298 typedef struct gzFile_s *gzFile; /* semi-opaque gzip file descriptor */
1305 but can also include a compression level ("wb9") or a strategy: 'f' for
1306 filtered data as in "wb6f", 'h' for Huffman-only compression as in "wb1h",
1307 'R' for run-length encoding as in "wb1R", or 'F' for fixed code compression
1328 reading, this will be detected automatically by looking for the magic two-
1351 double-close()ing the file descriptor. Both gzclose() and fclose() will
1357 provided, or '+' was provided), or if fd is -1. The file descriptor is not
1359 will not detect if fd is invalid (unless fd is -1).
1375 gzbuffer() returns 0 on success, or -1 on failure, such as being called
1380 int32_t zng_gzsetparams(gzFile file, int32_t level, int32_t strategy);
1382 Dynamically update the compression level and strategy for file. See the
1410 middle of a gzip stream. Note that gzread does not return -1 in the event
1417 len for end of file, or -1 for error. If len is too large to fit in an int,
1418 then nothing is read, -1 is returned, and the error state is set to
1441 and the end-of-file flag is set. The length of the partial item read is not
1445 file, resetting and retrying on end-of-file, when size is not 1.
1472 uncompressed bytes actually written, or a negative zlib error code in case
1478 zlib was compiled with the insecure functions sprintf() or vsprintf(),
1486 Compress and write the given null-terminated string s to file, excluding
1489 gzputs returns the number of characters written, or -1 in case of error.
1495 Read and decompress bytes from file into buf, until len-1 characters are
1497 end-of-file condition is encountered. If any characters are read or if len
1499 are read due to an end-of-file or len is less than one, then the buffer is
1502 gzgets returns buf which is a null-terminated string, or it returns NULL
1503 for end-of-file or in case of error. If there was an error, the contents at
1511 returns the value that was written, or -1 in case of error.
1517 Read and decompress one byte from file. gzgetc returns this byte or -1
1528 the next read. At least one character of push-back is always allowed.
1529 gzungetc() returns the character pushed, or -1 on failure. gzungetc() will
1530 fail if c is -1, and may fail if a character has been pushed but not read
1541 deflate() function. The return value is the zlib error number (see function
1567 the beginning of the uncompressed stream, or -1 in case of error, in
1598 be used for a progress indicator. On error, gzoffset() returns -1.
1604 Return true (1) if the end-of-file indicator for file has been set while
1605 reading, false (0) otherwise. Note that the end-of-file indicator is set
1613 unless the end-of-file indicator is reset by gzclearerr() and the input file
1635 linking statically, using gzdirect() will include all of the zlib code for
1660 using these instead of gzclose() is that they avoid linking in zlib
1664 zlib library.
1671 errnum is set to zlib error number. If an error occurred in the file system
1680 gzerror() should be used to distinguish errors from end-of-file for those
1687 Clear the error and end-of-file flags for file. This is analogous to the
1705 Update a running Adler-32 checksum with the bytes buf[0..len-1] and
1706 return the updated checksum. An Adler-32 value is in the range of a 32-bit
1710 An Adler-32 checksum is almost as reliable as a CRC-32 but can be computed
1732 Combine two Adler-32 checksums into one. For two sequences of bytes, seq1
1733 and seq2 with lengths len1 and len2, Adler-32 checksums were calculated for
1734 each, adler1 and adler2. adler32_combine() returns the Adler-32 checksum of
1743 Update a running CRC-32 with the bytes buf[0..len-1] and return the
1744 updated CRC-32. A CRC-32 value is in the range of a 32-bit unsigned integer.
1746 crc. Pre- and post-conditioning (one's complement) is performed within this
1769 Combine two CRC-32 check values into one. For two sequences of bytes,
1770 seq1 and seq2 with lengths len1 and len2, CRC-32 check values were
1771 calculated for each, crc1 and crc2. crc32_combine() returns the CRC-32
1794 /* zng_deflateInit and zng_inflateInit are macros to allow checking the zlib version
1797 Z_EXTERN Z_EXPORT int32_t zng_deflateInit_(zng_stream *strm, int32_t level, const char *version, in…
1799 Z_EXTERN Z_EXPORT int32_t zng_deflateInit2_(zng_stream *strm, int32_t level, int32_t method, int3…
1805 #define @ZLIB_SYMBOL_PREFIX@zng_deflateInit(strm, level) zng_deflateInit_((strm), (level), ZLIBNG_V…
1807 #define @ZLIB_SYMBOL_PREFIX@zng_deflateInit2(strm, level, method, windowBits, memLevel, strategy) \
1808 zng_deflateInit2_((strm), (level), (method), (windowBits), (memLevel), \
1829 # define @ZLIB_SYMBOL_PREFIX@zng_gzgetc(g) ((g)->have ? ((g)->have--, (g)->pos++, *((g)->next)++) …
1835 Z_DEFLATE_LEVEL = 0, /* compression level, represented as an int */
1840 … to trade reproducibility for e.g. improved performance or compression ratio, and non-0 means that
1841 …ity is strictly required. Reproducibility is guaranteed only when using an identical zlib-ng build.
1856 …Sets the values of the given zlib-ng deflate stream parameters. All the buffers are copied interna…
1868 …If there are no other errors, but at least one parameter is not supported by the current zlib-ng v…
1876 …Copies the values of the given zlib-ng deflate stream parameters into the user-provided buffers. R…
1877 …success, Z_VERSION_ERROR if at least one parameter is not supported by the current zlib-ng version…