gzbuffer分配的buffer在zlib中如何使用?

How is the buffer allocated by gzbuffer used in zlib?

试图了解如何在 zlib 中使用 gzbuffer。这是从手册中截取的(https://www.zlib.net/manual.html):

ZEXTERN int ZEXPORT gzbuffer OF((gzFile file, unsigned 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).

The new buffer size also affects the maximum length for gzprintf().

gzbuffer() returns 0 on success, or –1 on failure, such as being called too late.

所以分配了三倍的缓冲区大小。当我调用 gzwrite 时,是将压缩数据写入缓冲区(每次调用 gzwrite 时都会进行压缩)还是将未压缩数据写入缓冲区? (然后压缩被延迟,直到缓冲区被填满并且 gzflush 被内部调用,或者我自己调用 gzflush

当我继续调用gzwrite时,当缓冲区已满时会发生什么?此时是否分配了一些新的缓冲区内存,或者缓冲区只是刷新到文件然后重新使用?

读取时,分配一个size个输入缓冲区,分配一个2*size个输出缓冲区。写的时候,一样的,但是反过来了。

如果 len 小于 size in gzwrite(state, buf, len),则提供的数据进入输入缓冲区。一旦累积了 size 字节,该输入缓冲区就会被压缩。如果 len 大于或等于 size 缓冲区中剩余的内容将被压缩,然后是所有提供的 len 数据。如果请求刷新,则输入缓冲区中的所有数据都会被压缩。

压缩数据累积在size输出缓冲区中,每次累积size个压缩字节时写入,或者当gzFile刷新或关闭时写入。