Lines Matching +full:input +full:- +full:only

1 /* zlib.h -- interface of the 'zlib' general purpose compression library
4 Copyright (C) 1995-2024 Jean-loup Gailly and Mark Adler
6 This software is provided 'as-is', without any express or implied
22 Jean-loup Gailly Mark Adler
48 The 'zlib' compression library provides in-memory compression and
50 This version of the library supports only one compression method (deflation)
56 case, the application must provide more input and/or consume the output
59 The compressed data format used by default by the in-memory functions is
72 and on communications channels. The gzip format was designed for single-
78 even in the case of corrupted input.
87 z_const Bytef *next_in; /* next input byte */
89 uLong total_in; /* total number of input bytes read so far */
104 uLong adler; /* Adler-32 or CRC-32 value of the uncompressed data */
121 uInt extra_max; /* space at extra (only when reading header) */
122 Bytef *name; /* pointer to zero-terminated file name or Z_NULL */
123 uInt name_max; /* space at name (only when reading header) */
124 Bytef *comment; /* pointer to zero-terminated comment or Z_NULL */
125 uInt comm_max; /* space at comment (only when reading header) */
146 If zlib is used in a multi-threaded application, zalloc and zfree must be
147 thread safe. In that case, zlib is thread-safe. When zalloc and zfree are
151 On 16-bit systems, the functions zalloc and zfree must be able to allocate
158 the library with -DMAX_WBITS=14 (see zconf.h).
180 #define Z_ERRNO (-1)
181 #define Z_STREAM_ERROR (-2)
182 #define Z_DATA_ERROR (-3)
183 #define Z_MEM_ERROR (-4)
184 #define Z_BUF_ERROR (-5)
185 #define Z_VERSION_ERROR (-6)
193 #define Z_DEFAULT_COMPRESSION (-1)
210 /* The deflate compression method (the only one supported in this version) */
237 (the input data is simply copied a block at a time). Z_DEFAULT_COMPRESSION
252 deflate compresses as much data as possible, and stops when the input
254 some output latency (reading input without producing any output) except when
260 - Compress more input starting at next_in and update next_in and avail_in
261 accordingly. If not all input can be processed (because there is not
265 - Generate more output starting at next_out and update next_out and avail_out
268 should be set only when necessary. Some output may be provided even if
272 one of the actions is possible, by providing more input and/or consuming more
288 that the decompressor can get all input data available so far. (In
291 compression algorithms and so it should be used only when necessary. This
298 input data so far will be available to the decompressor, as for Z_SYNC_FLUSH.
321 avail_out), until the flush is complete (deflate returns with non-zero
326 If the parameter flush is set to Z_FINISH, pending input is processed,
330 avail_out) but no more input data, until it returns with Z_STREAM_END or an
331 error. After deflate has returned Z_STREAM_END, the only possible operations
341 deflate() sets strm->adler to the Adler-32 checksum of all input read
343 strm->adler will be the CRC-32 checksum of the input read so far. (See
346 deflate() may update strm->data_type if it can make a good guess about
347 the input data type (Z_BINARY or Z_TEXT). If in doubt, the data is
348 considered binary. This field is only for information purposes and does not
351 deflate() returns Z_OK if some progress has been made (more input
352 processed or more output produced), Z_STREAM_END if all input has been
353 consumed and all output has been produced (only when flush is set to
358 deflate() can be called again with more input and more output space to
366 This function discards any unprocessed input and does not flush any pending
371 prematurely (some input or output was discarded). In the error case, msg
382 the caller. In the current version of inflate, the provided input is not
396 implementation of inflateInit() does not process any header information --
403 inflate decompresses as much data as possible, and stops when the input
405 some output latency (reading input without producing any output) except when
411 - Decompress more input starting at next_in and update next_in and avail_in
412 accordingly. If not all input can be processed (because there is not
417 - Generate more output starting at next_out and update next_out and avail_out
419 no more input data or no more space in the output buffer (see below about
423 one of the actions is possible, by providing more input and/or consuming more
425 caller of inflate() does not provide both available input and available
443 To assist in this, on return inflate() always sets strm->data_type to the
444 number of unused bits in the last byte taken from strm->next_in, plus 64 if
446 128 if inflate() returned immediately after decoding an end-of-block code or
448 stream. The end-of-block will not be indicated until all of the uncompressed
449 data from that block has been written to strm->next_out. The number of
454 consumed input in bits.
460 256 is added to the value of strm->data_type when inflate() returns
466 this case all pending input is processed and all pending output is flushed;
487 below), inflate sets strm->adler to the Adler-32 checksum of the dictionary
489 strm->adler to the Adler-32 checksum of all output produced so far (that is,
491 below. At the end of the stream, inflate() checks that its computed Adler-32
493 only if the checksum is correct.
495 inflate() can decompress and check either zlib-wrapped or gzip-wrapped
499 gzip-wrapped deflate data, strm->adler32 is set to the CRC-32 of the output
500 produced so far. The CRC-32 is checked against the gzip trailer, as is the
503 inflate() returns Z_OK if some progress has been made (more input processed
506 preset dictionary is needed at this point, Z_DATA_ERROR if the input data was
507 corrupted (input stream not conforming to the zlib format or incorrect check
508 value, in which case strm->msg points to a string with a more specific
514 inflate() can be called again with more input and more output space to
524 This function discards any unprocessed input and does not flush any pending
535 The following functions are needed only in some special applications.
560 will result in 9 (a 512-byte window). In that case, providing 8 to
566 windowBits can also be -8..-15 for raw deflate. In this case, -windowBits
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
590 filter (or predictor), Z_HUFFMAN_ONLY to force Huffman encoding only (no
591 string match), or Z_RLE to limit match distances to one (run-length
598 strategy parameter only affects the compression ratio but not the
620 after the completion of a deflate block, i.e. after all input has been
641 Upon return of this function, strm->adler is set to the Adler-32 value
643 which dictionary has been used by the compressor. (The Adler-32 value
644 applies to the whole dictionary even if only a subset of the dictionary is
646 Adler-32 value is not computed and strm->adler is not set.
663 Z_NULL, then only the dictionary length is returned, and nothing is copied.
667 when more than the window size in input has been provided. It may return up
670 up to 258 bytes long. If the application needs the last window-size bytes of
671 input, then that would need to be saved by the application outside of zlib.
683 tried, for example when there are several ways of pre-processing the input
712 used to switch between compression and straight copy of the input data, or
713 to switch to a different kind of input data requiring a different strategy.
716 state was initialized or reset, then the input available so far is
730 Then no more input data should be provided before the deflateParams() call.
738 available input data before a change in the strategy or approach. Note that
750 Fine tune deflate's internal compression parameters. This should only be
752 searching for the best matching string, and even then only by the most
754 specific input data. Read the deflate.c source code for the meaning of the
769 sourceLen input bytes, an output buffer allocated to the size returned by
798 function can only be used for raw deflate, and must be used before the first
816 ignored -- the extra flags are set according to the compression level). The
820 the current versions of the command-line version of gzip (up through version
821 1.3.x) do not support header crc's, and will report that it is a "multi-part
847 size is given as input, inflate() will return with the error code
853 windowBits can also be -8..-15 for raw inflate. In this case, -windowBits
860 recommended that a check value such as an Adler-32 or a CRC-32 be applied to
867 detection, or add 16 to decode only the gzip format (the zlib format will
868 return a Z_DATA_ERROR). If a gzip stream is being decoded, strm->adler is a
869 CRC-32 instead of an Adler-32. Unlike the gunzip utility and gzread() (see
884 of inflateInit2() does not process any header information -- that is
895 can be determined from the Adler-32 value returned by that call of inflate.
906 expected one (incorrect Adler-32 value). inflateSetDictionary does not
919 Z_NULL, then only the dictionary length is returned, and nothing is copied.
930 available input is skipped. No output is provided.
937 Z_BUF_ERROR if no more input was provided, Z_DATA_ERROR if no flush point
941 the application may repeatedly call inflateSync, providing more input each
942 time, until success or end of the input data.
990 This function inserts bits in the inflate input stream. The intent is
993 from next_in. This function should only be used with raw inflate, and
996 least significant bits of value will be inserted in the input.
998 If bits is negative, then the input stream bit buffer is emptied. Then
1011 return value down 16 bits. If the upper value is -1 and the lower value is
1013 If the upper value is -1 and the lower value is non-zero, then inflate is in
1015 bytes from the input remaining to copy. If the upper value is not -1, then
1016 it is the number of bits back from the current bit position in the input of
1021 A code is being processed if inflate is waiting for more input to complete
1025 inflateMark() is used to mark locations in the input data for random
1028 location in the input stream can be determined from avail_in and data_type
1031 inflateMark returns the value noted above, or -65536 if the provided
1041 As inflate() processes the gzip stream, head->done is zero until the header
1042 is completed, at which time head->done is set to one. If a zlib stream is
1043 being decoded, then head->done is set to -1 to indicate that there will be
1081 before the call. If zalloc and zfree are Z_NULL, then the default library-
1105 inflateBack() does a raw inflate with a single call using a call-back
1106 interface for input and output. This is potentially more efficient than
1114 and to initialize the state with the user-provided window buffer.
1122 header and process the trailer on its own, hence this routine expects only
1128 called by inflateBack() for input and output. inflateBack() calls those
1133 number of bytes of provided input, and a pointer to that input in buf. If
1134 there is no input available, in() must return zero -- buf is ignored in that
1135 case -- and inflateBack() will return a buffer error. inflateBack() will
1136 call out(out_desc, buf, len) to write the uncompressed data buf[0..len-1].
1137 out() should return zero on success, or non-zero on failure. If out()
1138 returns non-zero, inflateBack() will return with an error. Neither in() nor
1141 The length written by out() will be at most the window size. Any non-zero
1142 amount of input may be provided by in().
1144 For convenience, inflateBack() can be provided input on the first call by
1145 setting strm->next_in and strm->avail_in. If that input is exhausted, then
1146 in() will be called. Therefore strm->next_in must be initialized before
1147 calling inflateBack(). If strm->next_in is Z_NULL, then in() will be called
1148 immediately for input. If strm->next_in is not Z_NULL, then strm->avail_in
1149 must also be initialized, and then if strm->avail_in is not zero, input will
1150 initially be taken from strm->next_in[0 .. strm->avail_in - 1].
1154 descriptors can be optionally used to pass any information that the caller-
1157 On return, inflateBack() will set strm->next_in and strm->avail_in to
1158 pass back any unused input that was provided by the last in() call. The
1161 in the deflate stream (in which case strm->msg is set to indicate the nature
1163 In the case of Z_BUF_ERROR, an input or output error can be distinguished
1164 using strm->next_in which will be Z_NULL only if in() returned an error. If
1165 strm->next_in is not Z_NULL, then the Z_BUF_ERROR was due to out() returning
1166 non-zero. (in() will always be called before out(), so strm->next_in is
1167 assured to be defined if out() returns non-zero.) Note that inflateBack()
1180 /* Return flags indicating compile-time options.
1190 9: ASMV or ASMINF -- use ASM code
1191 10: ZLIB_WINAPI -- exported functions use the WINAPI calling convention
1194 One-time table building (smaller code, but not thread-safe if true):
1195 12: BUILDFIXED -- build static block decoding tables when needed
1196 13: DYNAMIC_CRC_TABLE -- build CRC calculation tables when needed
1200 16: NO_GZCOMPRESS -- gz* functions cannot compress (to avoid linking
1202 17: NO_GZIP -- deflate can't write gzip streams, and inflate can't detect
1204 18-19: 0 (reserved)
1207 20: PKZIP_BUG_WORKAROUND -- slightly more permissive inflate
1208 21: FASTEST -- deflate algorithm with only one, lowest compression level
1212 24: 0 = vs*, 1 = s* -- 1 means limited to 20 arguments after the format
1213 25: 0 = *nprintf, 1 = *printf -- 1 means gzprintf() not secure!
1214 26: 0 = returns value, 1 = void -- 1 means inferred string length returned
1217 27-31: 0 (reserved)
1226 stream-oriented functions. To simplify the interface, some default options
1283 buffer, or Z_DATA_ERROR if the input data was corrupted or incomplete. In
1308 typedef struct gzFile_s *gzFile; /* semi-opaque gzip file descriptor */
1316 filtered data as in "wb6f", 'h' for Huffman-only compression as in "wb1h",
1317 'R' for run-length encoding as in "wb1R", or 'F' for fixed code compression
1338 reading, this will be detected automatically by looking for the magic two-
1360 double-close()ing the file descriptor. Both gzclose() and fclose() will
1366 provided, or '+' was provided), or if fd is -1. The file descriptor is not
1368 will not detect if fd is invalid (unless fd is -1).
1383 gzbuffer() returns 0 on success, or -1 on failure, such as being called
1401 the input file is not in gzip format, gzread copies the given number of
1404 After reaching the end of a gzip stream in the input, gzread will continue
1406 concatenated in the input file, and will all be decompressed by gzread().
1411 Upon reaching the end of the input, gzread will return with the available
1415 on the last gzread. Z_BUF_ERROR indicates that the input file ended in the
1416 middle of a gzip stream. Note that gzread does not return -1 in the event
1423 len for end of file, or -1 for error. If len is too large to fit in an int,
1424 then nothing is read, -1 is returned, and the error state is set to
1444 In the event that the end of file is reached and only a partial item is
1447 and the end-of-file flag is set. The length of the partial item read is not
1451 file, resetting and retrying on end-of-file, when size is not 1.
1483 buffer overflow with unpredictable consequences, which is possible only if
1491 Compress and write the given null-terminated string s to file, excluding
1494 gzputs returns the number of characters written, or -1 in case of error.
1499 Read and decompress bytes from file into buf, until len-1 characters are
1501 end-of-file condition is encountered. If any characters are read or if len
1503 are read due to an end-of-file or len is less than one, then the buffer is
1506 gzgets returns buf which is a null-terminated string, or it returns NULL
1507 for end-of-file or in case of error. If there was an error, the contents at
1514 returns the value that was written, or -1 in case of error.
1519 Read and decompress one byte from file. gzgetc returns this byte or -1
1529 the next read. At least one character of push-back is always allowed.
1530 gzungetc() returns the character pushed, or -1 on failure. gzungetc() will
1531 fail if c is -1, and may fail if a character has been pushed but not read
1542 gzerror below). gzflush is only permitted when writing.
1549 gzflush should be called only when strictly necessary because it will
1563 extremely slow. If the file is opened for writing, only forward seeks are
1568 the beginning of the uncompressed stream, or -1 in case of error, in
1575 Rewind file. This function is supported only for reading.
1597 offset does not include as yet unused buffered input. This information can
1598 be used for a progress indicator. On error, gzoffset() returns -1.
1603 Return true (1) if the end-of-file indicator for file has been set while
1604 reading, false (0) otherwise. Note that the end-of-file indicator is set
1605 only if the read tried to go past the end of the input, but came up short.
1608 number of bytes remaining in the input file. This will happen if the input
1612 unless the end-of-file indicator is reset by gzclearerr() and the input file
1621 If the input file is empty, gzdirect() will return true, since the input
1653 Same as gzclose(), but gzclose_r() is only for use when reading, and
1654 gzclose_w() is only for use when writing or appending. The advantage to
1656 compression or decompression code that is not used when only reading or only
1674 gzerror() should be used to distinguish errors from end-of-file for those
1680 Clear the error and end-of-file flags for file. This is analogous to the
1697 Update a running Adler-32 checksum with the bytes buf[0..len-1] and
1698 return the updated checksum. An Adler-32 value is in the range of a 32-bit
1702 An Adler-32 checksum is almost as reliable as a CRC-32 but can be computed
1725 Combine two Adler-32 checksums into one. For two sequences of bytes, seq1
1726 and seq2 with lengths len1 and len2, Adler-32 checksums were calculated for
1727 each, adler1 and adler2. adler32_combine() returns the Adler-32 checksum of
1728 seq1 and seq2 concatenated, requiring only adler1, adler2, and len2. Note
1735 Update a running CRC-32 with the bytes buf[0..len-1] and return the
1736 updated CRC-32. A CRC-32 value is in the range of a 32-bit unsigned integer.
1738 crc. Pre- and post-conditioning (one's complement) is performed within this
1760 Combine two CRC-32 check values into one. For two sequences of bytes,
1761 seq1 and seq2 with lengths len1 and len2, CRC-32 check values were
1762 calculated for each, crc1 and crc2. crc32_combine() returns the CRC-32
1763 check value of seq1 and seq2 concatenated, requiring only crc1, crc2, and
1764 len2. len2 must be non-negative.
1771 crc32_combine_op(). len2 must be non-negative.
1840 * only be used by the gzgetc() macro. You have been warned.
1851 ((g)->have ? ((g)->have--, (g)->pos++, *((g)->next)++) : (gzgetc)(g))
1854 ((g)->have ? ((g)->have--, (g)->pos++, *((g)->next)++) : (gzgetc)(g))
1857 /* provide 64-bit offset functions if _LARGEFILE64_SOURCE defined, and/or
1860 * functions are changed to 64 bits) -- in case these are set on systems