summaryrefslogtreecommitdiff
path: root/libphobos/src/etc/c/zlib.d
diff options
context:
space:
mode:
Diffstat (limited to 'libphobos/src/etc/c/zlib.d')
-rw-r--r--libphobos/src/etc/c/zlib.d211
1 files changed, 114 insertions, 97 deletions
diff --git a/libphobos/src/etc/c/zlib.d b/libphobos/src/etc/c/zlib.d
index a1b20fedce9..73c6534d8da 100644
--- a/libphobos/src/etc/c/zlib.d
+++ b/libphobos/src/etc/c/zlib.d
@@ -2,15 +2,16 @@
/* updated from 1.2.1 to 1.2.3 by Thomas Kuehne */
/* updated from 1.2.3 to 1.2.8 by Dmitry Atamanov */
/* updated from 1.2.8 to 1.2.11 by Iain Buclaw */
+/* updated from 1.2.11 to 1.2.12 by Brian Callahan */
module etc.c.zlib;
import core.stdc.config;
/* zlib.h -- interface of the 'zlib' general purpose compression library
- version 1.2.11, January 15th, 2017
+ version 1.2.12, March 11th, 2022
- Copyright (C) 1995-2017 Jean-loup Gailly and Mark Adler
+ Copyright (C) 1995-2022 Jean-loup Gailly and Mark Adler
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
@@ -42,8 +43,8 @@ nothrow:
extern (C):
// Those are extern(D) as they should be mangled
-extern(D) immutable string ZLIB_VERSION = "1.2.11";
-extern(D) immutable ZLIB_VERNUM = 0x12b0;
+extern(D) immutable string ZLIB_VERSION = "1.2.12";
+extern(D) immutable ZLIB_VERNUM = 0x12c0;
/*
The 'zlib' compression library provides in-memory compression and
@@ -566,8 +567,7 @@ int deflateInit2(z_streamp strm,
}
/*
This is another version of deflateInit with more compression options. The
- fields next_in, zalloc, zfree and opaque must be initialized before by the
- caller.
+ fields zalloc, zfree and opaque must be initialized before by the caller.
The method parameter is the compression method. It must be Z_DEFLATED in
this version of the library.
@@ -586,7 +586,7 @@ int deflateInit2(z_streamp strm,
with deflateInit2() with this initialization, or at least in that case use 9
with inflateInit2().
- windowBits can also be -8..-15 for raw deflate. In this case, -windowBits
+ windowBits can also be -8 .. -15 for raw deflate. In this case, -windowBits
determines the window size. deflate() will then generate raw deflate data
with no zlib header or trailer, and will not compute a check value.
@@ -728,11 +728,12 @@ int deflateParams(z_streamp strm, int level, int strategy);
used to switch between compression and straight copy of the input data, or
to switch to a different kind of input data requiring a different strategy.
If the compression approach (which is a function of the level) or the
- strategy is changed, and if any input has been consumed in a previous
- deflate() call, then the input available so far is compressed with the old
- level and strategy using deflate(strm, Z_BLOCK). There are three approaches
- for the compression levels 0, 1 .. 3, and 4 .. 9 respectively. The new level
- and strategy will take effect at the next call of deflate().
+ strategy is changed, and if there have been any deflate() calls since the
+ state was initialized or reset, then the input available so far is
+ compressed with the old level and strategy using deflate(strm, Z_BLOCK).
+ There are three approaches for the compression levels 0, 1 .. 3, and 4 .. 9
+ respectively. The new level and strategy will take effect at the next call
+ of deflate().
If a deflate(strm, Z_BLOCK) is performed by deflateParams(), and it does
not have enough output space to complete, then the parameter change will not
@@ -856,7 +857,7 @@ int inflateInit2(z_streamp strm, int windowBits)
windowBits can also be zero to request that inflate use the window size in
the zlib header of the compressed stream.
- windowBits can also be -8..-15 for raw inflate. In this case, -windowBits
+ windowBits can also be -8 .. -15 for raw inflate. In this case, -windowBits
determines the window size. inflate() will then process raw deflate data,
not looking for a zlib or gzip header, not generating a check value, and not
looking for any check values for comparison at the end of the stream. This
@@ -873,9 +874,11 @@ int inflateInit2(z_streamp strm, int windowBits)
detection, or add 16 to decode only the gzip format (the zlib format will
return a Z_DATA_ERROR). If a gzip stream is being decoded, strm->adler is a
CRC-32 instead of an Adler-32. Unlike the gunzip utility and gzread() (see
- below), inflate() will not automatically decode concatenated gzip streams.
- inflate() will return Z_STREAM_END at the end of the gzip stream. The state
- would need to be reset to continue decoding a subsequent gzip stream.
+ below), inflate() will *not* automatically decode concatenated gzip members.
+ inflate() will return Z_STREAM_END at the end of the gzip member. The state
+ would need to be reset to continue decoding a subsequent gzip member. This
+ *must* be done if there is more data after a gzip member, in order for the
+ decompression to be compliant with the gzip standard (RFC 1952).
inflateInit2 returns Z_OK if success, Z_MEM_ERROR if there was not enough
memory, Z_VERSION_ERROR if the zlib library version is incompatible with the
@@ -1311,14 +1314,14 @@ alias z_size_t = size_t;
gzFile gzopen(const(char)* path, const(char)* mode);
/*
- Opens a gzip (.gz) file for reading or writing. The mode parameter is as
- in fopen ("rb" or "wb") but can also include a compression level ("wb9") or
- a strategy: 'f' for filtered data as in "wb6f", 'h' for Huffman-only
- compression as in "wb1h", 'R' for run-length encoding as in "wb1R", or 'F'
- for fixed code compression as in "wb9F". (See the description of
- deflateInit2 for more information about the strategy parameter.) 'T' will
- request transparent writing or appending with no compression and not using
- the gzip format.
+ Open the gzip (.gz) file at path for reading and decompressing, or
+ compressing and writing. The mode parameter is as in fopen ("rb" or "wb")
+ but can also include a compression level ("wb9") or a strategy: 'f' for
+ filtered data as in "wb6f", 'h' for Huffman-only compression as in "wb1h",
+ 'R' for run-length encoding as in "wb1R", or 'F' for fixed code compression
+ as in "wb9F". (See the description of deflateInit2 for more information
+ about the strategy parameter.) 'T' will request transparent writing or
+ appending with no compression and not using the gzip format.
"a" can be used instead of "w" to request that the gzip stream that will
be written be appended to the file. "+" will result in an error, since
@@ -1348,9 +1351,9 @@ gzFile gzopen(const(char)* path, const(char)* mode);
gzFile gzdopen(int fd, const(char)* mode);
/*
- gzdopen associates a gzFile with the file descriptor fd. File descriptors
- are obtained from calls like open, dup, creat, pipe or fileno (if the file
- has been previously opened with fopen). The mode parameter is as in gzopen.
+ Associate a gzFile with the file descriptor fd. File descriptors are
+ obtained from calls like open, dup, creat, pipe or fileno (if the file has
+ been previously opened with fopen). The mode parameter is as in gzopen.
The next call of gzclose on the returned gzFile will also close the file
descriptor fd, just like fclose(fdopen(fd, mode)) closes the file descriptor
@@ -1371,13 +1374,13 @@ gzFile gzdopen(int fd, const(char)* mode);
int gzbuffer(gzFile file, uint size);
/*
- Set the internal buffer size used by this library's functions. The
- default buffer size is 8192 bytes. This function must be called after
- gzopen() or gzdopen(), and before any other calls that read or write the
- file. The buffer memory allocation is always deferred to the first read or
- write. Three times that size in buffer space is allocated. A larger buffer
- size of, for example, 64K or 128K bytes will noticeably increase the speed
- of decompression (reading).
+ Set the internal buffer size used by this library's functions for file to
+ size. The default buffer size is 8192 bytes. This function must be called
+ after gzopen() or gzdopen(), and before any other calls that read or write
+ the file. The buffer memory allocation is always deferred to the first read
+ or write. Three times that size in buffer space is allocated. A larger
+ buffer size of, for example, 64K or 128K bytes will noticeably increase the
+ speed of decompression (reading).
The new buffer size also affects the maximum length for gzprintf().
@@ -1387,9 +1390,9 @@ int gzbuffer(gzFile file, uint size);
int gzsetparams(gzFile file, int level, int strategy);
/*
- Dynamically update the compression level or strategy. See the description
- of deflateInit2 for the meaning of these parameters. Previously provided
- data is flushed before the parameter change.
+ Dynamically update the compression level and strategy for file. See the
+ description of deflateInit2 for the meaning of these parameters. Previously
+ provided data is flushed before applying the parameter changes.
gzsetparams returns Z_OK if success, Z_STREAM_ERROR if the file was not
opened for writing, Z_ERRNO if there is an error writing the flushed data,
@@ -1398,7 +1401,7 @@ int gzsetparams(gzFile file, int level, int strategy);
int gzread(gzFile file, void* buf, uint len);
/*
- Reads the given number of uncompressed bytes from the compressed file. If
+ Read and decompress up to len uncompressed bytes from file into buf. If
the input file is not in gzip format, gzread copies the given number of
bytes into the buffer directly from the file.
@@ -1428,11 +1431,11 @@ int gzread(gzFile file, void* buf, uint len);
z_size_t gzfread(void* buf, z_size_t size, z_size_t nitems, gzFile file);
/*
- Read up to nitems items of size size from file to buf, otherwise operating
- as gzread() does. This duplicates the interface of stdio's fread(), with
- size_t request and return types. If the library defines size_t, then
- z_size_t is identical to size_t. If not, then z_size_t is an unsigned
- integer type that can contain a pointer.
+ Read and decompress up to nitems items of size size from file into buf,
+ otherwise operating as gzread() does. This duplicates the interface of
+ stdio's fread(), with size_t request and return types. If the library
+ defines size_t, then z_size_t is identical to size_t. If not, then z_size_t
+ is an unsigned integer type that can contain a pointer.
gzfread() returns the number of full items read of size size, or zero if
the end of the file was reached and a full item could not be read, or if
@@ -1453,14 +1456,13 @@ z_size_t gzfread(void* buf, z_size_t size, z_size_t nitems, gzFile file);
int gzwrite(gzFile file, void* buf, uint len);
/*
- Writes the given number of uncompressed bytes into the compressed file.
- gzwrite returns the number of uncompressed bytes written or 0 in case of
- error.
+ Compress and write the len uncompressed bytes at buf to file. gzwrite
+ returns the number of uncompressed bytes written or 0 in case of error.
*/
z_size_t gzfwrite(void* buf, z_size_t size, z_size_t nitems, gzFile file);
/*
- gzfwrite() writes nitems items of size size from buf to file, duplicating
+ Compress and write nitems items of size size from buf to file, duplicating
the interface of stdio's fwrite(), with size_t request and return types. If
the library defines size_t, then z_size_t is identical to size_t. If not,
then z_size_t is an unsigned integer type that can contain a pointer.
@@ -1473,22 +1475,22 @@ z_size_t gzfwrite(void* buf, z_size_t size, z_size_t nitems, gzFile file);
int gzprintf(gzFile file, const(char)* format, ...);
/*
- Converts, formats, and writes the arguments to the compressed file under
- control of the format string, as in fprintf. gzprintf returns the number of
+ Convert, format, compress, and write the arguments (...) to file under
+ control of the string format, as in fprintf. gzprintf returns the number of
uncompressed bytes actually written, or a negative zlib error code in case
of error. The number of uncompressed bytes written is limited to 8191, or
one less than the buffer size given to gzbuffer(). The caller should assure
that this limit is not exceeded. If it is exceeded, then gzprintf() will
return an error (0) with nothing written. In this case, there may also be a
buffer overflow with unpredictable consequences, which is possible only if
- zlib was compiled with the insecure functions sprintf() or vsprintf()
+ zlib was compiled with the insecure functions sprintf() or vsprintf(),
because the secure snprintf() or vsnprintf() functions were not available.
This can be determined using zlibCompileFlags().
*/
int gzputs(gzFile file, const(char)* s);
/*
- Writes the given null-terminated string to the compressed file, excluding
+ Compress and write the given null-terminated string s to file, excluding
the terminating null character.
gzputs returns the number of characters written, or -1 in case of error.
@@ -1496,11 +1498,12 @@ int gzputs(gzFile file, const(char)* s);
const(char)* gzgets(gzFile file, const(char)* buf, int len);
/*
- Reads bytes from the compressed file until len-1 characters are read, or a
- newline character is read and transferred to buf, or an end-of-file
- condition is encountered. If any characters are read or if len == 1, the
- string is terminated with a null character. If no characters are read due
- to an end-of-file or len < 1, then the buffer is left untouched.
+ Read and decompress bytes from file into buf, until len-1 characters are
+ read, or until a newline character is read and transferred to buf, or an
+ end-of-file condition is encountered. If any characters are read or if len
+ is one, the string is terminated with a null character. If no characters
+ are read due to an end-of-file or len is less than one, then the buffer is
+ left untouched.
gzgets returns buf which is a null-terminated string, or it returns NULL
for end-of-file or in case of error. If there was an error, the contents at
@@ -1509,13 +1512,13 @@ const(char)* gzgets(gzFile file, const(char)* buf, int len);
int gzputc(gzFile file, int c);
/*
- Writes c, converted to an unsigned char, into the compressed file. gzputc
+ Compress and write c, converted to an unsigned char, into file. gzputc
returns the value that was written, or -1 in case of error.
*/
int gzgetc(gzFile file);
/*
- Reads one byte from the compressed file. gzgetc returns this byte or -1
+ Read and decompress one byte from file. gzgetc returns this byte or -1
in case of end of file or error. This is implemented as a macro for speed.
As such, it does not do all of the checking the other functions do. I.e.
it does not check to see if file is NULL, nor whether the structure file
@@ -1524,8 +1527,8 @@ int gzgetc(gzFile file);
int gzungetc(int c, gzFile file);
/*
- Push one character back onto the stream to be read as the first character
- on the next read. At least one character of push-back is allowed.
+ Push c back onto the stream for file to be read as the first character on
+ the next read. At least one character of push-back is always allowed.
gzungetc() returns the character pushed, or -1 on failure. gzungetc() will
fail if c is -1, and may fail if a character has been pushed but not read
yet. If gzungetc is used immediately after gzopen or gzdopen, at least the
@@ -1536,9 +1539,9 @@ int gzungetc(int c, gzFile file);
int gzflush(gzFile file, int flush);
/*
- Flushes all pending output into the compressed file. The parameter flush
- is as in the deflate() function. The return value is the zlib error number
- (see function gzerror below). gzflush is only permitted when writing.
+ Flush all pending output to file. The parameter flush is as in the
+ deflate() function. The return value is the zlib error number (see function
+ gzerror below). gzflush is only permitted when writing.
If the flush parameter is Z_FINISH, the remaining data is written and the
gzip stream is completed in the output. If gzwrite() is called again, a new
@@ -1551,8 +1554,8 @@ int gzflush(gzFile file, int flush);
z_off_t gzseek(gzFile file, z_off_t offset, int whence);
/*
- Sets the starting position for the next gzread or gzwrite on the given
- compressed file. The offset represents a number of bytes in the
+ Set the starting position to offset relative to whence for the next gzread
+ or gzwrite on file. The offset represents a number of bytes in the
uncompressed data stream. The whence parameter is defined as in lseek(2);
the value SEEK_END is not supported.
@@ -1569,39 +1572,39 @@ z_off_t gzseek(gzFile file, z_off_t offset, int whence);
int gzrewind(gzFile file);
/*
- Rewinds the given file. This function is supported only for reading.
+ Rewind file. This function is supported only for reading.
- gzrewind(file) is equivalent to (int)gzseek(file, 0L, SEEK_SET)
+ gzrewind(file) is equivalent to (int)gzseek(file, 0L, SEEK_SET).
*/
z_off_t gztell(gzFile file);
/*
- Returns the starting position for the next gzread or gzwrite on the given
- compressed file. This position represents a number of bytes in the
- uncompressed data stream, and is zero when starting, even if appending or
- reading a gzip stream from the middle of a file using gzdopen().
+ Return the starting position for the next gzread or gzwrite on file.
+ This position represents a number of bytes in the uncompressed data stream,
+ and is zero when starting, even if appending or reading a gzip stream from
+ the middle of a file using gzdopen().
gztell(file) is equivalent to gzseek(file, 0L, SEEK_CUR)
*/
z_off_t gzoffset(gzFile file);
/*
- Returns the current offset in the file being read or written. This offset
- includes the count of bytes that precede the gzip stream, for example when
- appending or when using gzdopen() for reading. When reading, the offset
- does not include as yet unused buffered input. This information can be used
- for a progress indicator. On error, gzoffset() returns -1.
+ Return the current compressed (actual) read or write offset of file. This
+ offset includes the count of bytes that precede the gzip stream, for example
+ when appending or when using gzdopen() for reading. When reading, the
+ offset does not include as yet unused buffered input. This information can
+ be used for a progress indicator. On error, gzoffset() returns -1.
*/
int gzeof(gzFile file);
/*
- Returns true (1) if the end-of-file indicator has been set while reading,
- false (0) otherwise. Note that the end-of-file indicator is set only if the
- read tried to go past the end of the input, but came up short. Therefore,
- just like feof(), gzeof() may return false even if there is no more data to
- read, in the event that the last read request was for the exact number of
- bytes remaining in the input file. This will happen if the input file size
- is an exact multiple of the buffer size.
+ Return true (1) if the end-of-file indicator for file has been set while
+ reading, false (0) otherwise. Note that the end-of-file indicator is set
+ only if the read tried to go past the end of the input, but came up short.
+ Therefore, just like feof(), gzeof() may return false even if there is no
+ more data to read, in the event that the last read request was for the exact
+ number of bytes remaining in the input file. This will happen if the input
+ file size is an exact multiple of the buffer size.
If gzeof() returns true, then the read functions will return no more data,
unless the end-of-file indicator is reset by gzclearerr() and the input file
@@ -1610,7 +1613,7 @@ int gzeof(gzFile file);
int gzdirect(gzFile file);
/*
- Returns true (1) if file is being copied directly while reading, or false
+ Return true (1) if file is being copied directly while reading, or false
(0) if file is a gzip stream being decompressed.
If the input file is empty, gzdirect() will return true, since the input
@@ -1631,8 +1634,8 @@ int gzdirect(gzFile file);
int gzclose(gzFile file);
/*
- Flushes all pending output if necessary, closes the compressed file and
- deallocates the (de)compression state. Note that once file is closed, you
+ Flush all pending output for file, if necessary, close file and
+ deallocate the (de)compression state. Note that once file is closed, you
cannot call gzerror with file, since its structures have been deallocated.
gzclose must not be called more than once on the same file, just as free
must not be called more than once on the same allocation.
@@ -1656,10 +1659,10 @@ int gzclose_w(gzFile file);
const(char)* gzerror(gzFile file, int* errnum);
/*
- Returns the error message for the last error which occurred on the given
- compressed file. errnum is set to zlib error number. If an error occurred
- in the file system and not in the compression library, errnum is set to
- Z_ERRNO and the application may consult errno to get the exact error code.
+ Return the error message for the last error which occurred on file.
+ errnum is set to zlib error number. If an error occurred in the file system
+ and not in the compression library, errnum is set to Z_ERRNO and the
+ application may consult errno to get the exact error code.
The application must not modify the returned string. Future calls to
this function may invalidate the previously returned string. If file is
@@ -1672,7 +1675,7 @@ const(char)* gzerror(gzFile file, int* errnum);
void gzclearerr(gzFile file);
/*
- Clears the error and end-of-file flags for file. This is analogous to the
+ Clear the error and end-of-file flags for file. This is analogous to the
clearerr() function in stdio. This is useful for continuing to read a gzip
file that is being written concurrently.
*/
@@ -1688,8 +1691,9 @@ void gzclearerr(gzFile file);
uint adler32(uint adler, const(ubyte)* buf, uint len);
/*
Update a running Adler-32 checksum with the bytes buf[0 .. len-1] and
- return the updated checksum. If buf is Z_NULL, this function returns the
- required initial value for the checksum.
+ return the updated checksum. An Adler-32 value is in the range of a 32-bit
+ unsigned integer. If buf is Z_NULL, this function returns the required
+ initial value for the checksum.
An Adler-32 checksum is almost as reliable as a CRC-32 but can be computed
much faster.
@@ -1722,9 +1726,10 @@ uint adler32_combine(uint adler1, uint adler2, z_off_t len2);
uint crc32(uint crc, const(ubyte)* buf, uint len);
/*
Update a running CRC-32 with the bytes buf[0 .. len-1] and return the
- updated CRC-32. If buf is Z_NULL, this function returns the required
- initial value for the crc. Pre- and post-conditioning (one's complement) is
- performed within this function so it shouldn't be done by the application.
+ updated CRC-32. A CRC-32 value is in the range of a 32-bit unsigned integer.
+ If buf is Z_NULL, this function returns the required initial value for the
+ crc. Pre- and post-conditioning (one's complement) is performed within this
+ function so it shouldn't be done by the application.
Usage example:
@@ -1736,7 +1741,7 @@ uint crc32(uint crc, const(ubyte)* buf, uint len);
if (crc != original_crc) error();
*/
-uint crc32_z(uint adler, const(ubyte)* buf, z_size_t len);
+uint crc32_z(uint crc, const(ubyte)* buf, z_size_t len);
/*
Same as crc32(), but with a size_t length.
*/
@@ -1751,6 +1756,18 @@ uint crc32_combine(uint crc1, uint crc2, z_off_t len2);
len2.
*/
+uint crc32_combine_gen(z_off_t len2);
+/*
+ Return the operator corresponding to length len2, to be used with
+ crc32_combine_op().
+*/
+
+uint crc32_combine_op(uint crc1, uint crc2, uint op);
+/*
+ Give the same result as crc32_combine(), using op in place of len2. op is
+ is generated from len2 by crc32_combine_gen(). This will be faster than
+ crc32_combine() if the generated op is used more than once.
+*/
/* various hacks, don't look :) */