如何让 zlib 输出 gzip 页脚

How do I have zlib output the gzip footer?

本文关键字:gzip 页脚 输出 zlib      更新时间:2023-10-16
如何

让 zlib 为我输出 gzip 页脚?我目前正在自己做,但如果 zlib 能为我做就好了。

shared_data xcc_z::gzip(data_ref s)
{
  z_stream stream;
  stream.zalloc = NULL;
  stream.zfree = NULL;
  stream.opaque = NULL;
  if (deflateInit2(&stream, Z_DEFAULT_COMPRESSION, Z_DEFLATED, 16 + MAX_WBITS, MAX_MEM_LEVEL, Z_DEFAULT_STRATEGY))
  {
    assert(false);
    return {};
  }
  shared_data d(deflateBound(&stream, s.size()) + 8);
  stream.next_in = const_cast<unsigned char*>(s.data());
  stream.avail_in = s.size();
  stream.next_out = d.data();
  stream.avail_out = d.size() - 8;
  deflate(&stream, Z_FINISH);
  deflateEnd(&stream);
  unsigned char* w = stream.next_out;
    w = write_int_le(4, w, crc32(crc32(0, NULL, 0), s.data(), s.size()));
    w = write_int_le(4, w, s.size());
    return d.substr(0, w - d.data());
}

为什么你认为它没有?您的代码在 zlib 已经编写的预告片之后附加了一个无用的第二个预告片。