dousi6405
2009-05-30 13:50
浏览 169
已采纳

获取zlib中未压缩数据的大小?

I'm creating something that includes a file upload service of sorts, and I need to store data compressed with zlib's compress() function. I send it across the internet already compressed, but I need to know the uncompressed file size on the remote server. Is there any way I can figure out this information without uncompress()ing the data on the server first, just for efficiency? That's how I'm doing it now, but if there's a shortcut I'd love to take it.

By the way, why is it called uncompress? That sounds pretty terrible to me, I always thought it would be decompress...

图片转代码服务由CSDN问答提供 功能建议

我正在创建包含各种文件上传服务的东西,我需要存储使用zlib压缩的数据压缩 ()函数。 我通过互联网发送它已经压缩,但我需要知道远程服务器上未压缩的文件大小。 有没有办法在没有首先解压缩服务器上的数据的情况下找出这些信息,只是为了提高效率? 这就是我现在正在做的事情,但是如果有一条捷径我很乐意接受它。

顺便说一下,为什么它被称为uncompress? 这对我来说听起来很糟糕,我一直以为它会解压缩......

  • 写回答
  • 好问题 提建议
  • 追加酬金
  • 关注问题
  • 邀请回答

3条回答 默认 最新

  • drcmue4619 2009-05-30 15:19
    最佳回答

    The zlib format doesn't have a field for the original input size, so I doubt you will be able to do that without simulating a decompression of the data. The gzip format has a "input size" (ISIZE) field, that you could use, but maybe you want to avoid changing the compression format or having the clients sending the file size.

    But even if you use a different format, if you don't trust the clients you would still need to run a more expensive check to make sure the uncompressed data is the size the client says it is. In this case, what you can do is to make the uncompress-to-/dev/null process less expensive, making sure zlib doesn't write the output data anywhere, as you just want to know the uncompressed size.

    评论
    解决 无用
    打赏 举报
查看更多回答(2条)

相关推荐 更多相似问题