开发者

zlib: Decompressed File Size?

开发者 https://www.devze.com 2023-01-03 23:01 出处:网络
I\'m using zlib to decompress a file. I want to verify that there is enough disk space to unzip the f开发者_如何学编程ile. Do the zip format and zlib provide facilities to determine the decompressed s

I'm using zlib to decompress a file. I want to verify that there is enough disk space to unzip the f开发者_如何学编程ile. Do the zip format and zlib provide facilities to determine the decompressed size of its contents?


If your file was compressed using the gzip format (RFC1952), then the last 4 bytes, the ISIZE field indicates the uncompressed file size mod 2^32. Therefore, provided that the original file was smaller than 4GB, you can determine its size by reading the last 4 bytes. Check the man pages for gunzip.

If ZLIB or raw Deflate format was used, you will have to decompress first to determine the uncompressed size.


Just create a simple file structure for compressing:

{
FileFormatHeader (optional) x bytes
OriginalSize (4 or 8 bytes)
CompressedSize (optional) (4 or 8 bytes)
HashSum (optional) (16 bytes or different number [depends on hash algorithm])

CompressedData
}

Now you have all the information that you need for decompressing

0

精彩评论

暂无评论...
验证码 换一张
取 消