zlib.reset()


对于压缩和解压流,将压缩器/解压器重置为出厂默认设置。

🌐 For inflate and deflate streams, reset the compressor/decompressor to factory defaults.

对于 Brotli 流,可以在保留已配置的参数和字典的情况下,开始新的压缩或解压缩会话。

🌐 For Brotli streams, start a new compression or decompression session while preserving the configured parameters and dictionary.

对于 Zstd 流,取消当前帧并开始一个新会话,同时保留已配置的参数和字典。如果 pledgedSrcSize 已配置用于 Zstd 压缩器,它将在下一帧中再次适用。

🌐 For Zstd streams, cancel the current frame and start a new session while preserving the configured parameters and dictionary. If pledgedSrcSize was configured for a Zstd compressor, it applies again to the next frame.

在 gzip 流输出了不完整成员后重置流,会导致流报 ERR_ZLIB_INCOMPLETE_FRAME 错误。在此时重置会丢弃成员状态,而已写出的字节仍保留在输出流的开头,导致无法解码。应该调用 .end(),或者重新开始一个新的 gzip 流。封装在 zlib 中的 deflate 在刷新后仍可能 reset();重用压缩器的调用者会丢弃第一次的输出。原始 deflate 没有封装头,所以刷新后 reset() 仍会进行拼接。

🌐 Resetting a gzip stream after it has emitted output for an incomplete member causes the stream to error with ERR_ZLIB_INCOMPLETE_FRAME. Resetting at that point would discard the member state while the bytes already written out remain at the start of the output stream, leaving it undecodable. Call .end(), or start over with a new gzip stream, instead. zlib-wrapped deflate may still reset() after a flush; callers that reuse the compressor discard the first output. Raw deflate has no wrapper header, so reset() after a flush still concatenates.

在写入进行时调用 reset() 会抛出 Error。

🌐 Calling reset() while a write is in progress throws an Error.

在 Zstd 压缩帧未完成但已生成输出后重置它,会导致流出现 ERR_ZLIB_INCOMPLETE_FRAME 错误。在那时候重置会丢弃帧状态,而已写出的字节仍然在输出流的开头,导致无法解码。你应该调用 .end(),或者从一个新的流重新开始。

🌐 Resetting an incomplete Zstd compression frame after it has emitted output causes the stream to error with ERR_ZLIB_INCOMPLETE_FRAME. Resetting at that point would discard the frame state while the bytes already written out remain at the start of the output stream, leaving it undecodable. Call .end(), or start over with a new stream, instead.