Reputation: 11
I'm using zlib to decompress a file. I want to verify that there is enough disk space to unzip the file. Do the zip format and zlib provide facilities to determine the decompressed size of its contents?
Upvotes: 1
Views: 2254
Reputation: 443
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.
Upvotes: 1
Reputation: 984
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
Upvotes: 0