Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get size of packed file in 7-zip archive

Tags:

c#

7zip

I'm using SevenZipSharp and it has Size property in ArchiveFileInfo struct, that "Gets or sets size of the file (unpacked)".

How can I get size of packed file in archive?

like image 220
a1bT Avatar asked Dec 21 '15 06:12

a1bT


People also ask

How do I know the size of a compressed file?

Use the GetCompressedFileSize function to obtain the compressed size of a file. If the file is compressed, its compressed size will be less than its uncompressed size. Use the GetFileSize function to determine the uncompressed size of a file.

Does 7zip reduce file size?

7-Zip is a free and open-source file archiver for compressing and uncompressing files. If you need to save some disk space or make your files more portable, this software can compress your files into an archive with a . 7z extension.

Is 7-zip faster than Windows zip?

WinRAR and WinZip compression speeds, 7-Zip is typically a little slower. The program will give you a file size around 40% of the original file. Like WinZip, 7-Zip offers AES-256 password-protected encryption in the ZIP format, but it also offers this encryption in 7z.


1 Answers

Unfortunately it seems that SevenZipSharp doesn't fill this info. Here's for example how it fills unpacked size in ArchiveFileInfo:

var fileInfo = new ArchiveFileInfo { Index = (int)i };
...
_archive.GetProperty(i, ItemPropId.Size, ref data);
fileInfo.Size = NativeMethods.SafeCast<ulong>(data, 0);

ItemPropId enum has PackedSize property which is not used though, I suppose due to the fact it may be absent (according to the comment):

/// <summary>
/// Item packed sise; usually absent
/// </summary>
PackedSize,

So I guess the only way to get it is to fork SevenZipSharp and try to fix it yourself (or search for an already existing fork). If it's possible at all.

like image 140
andreycha Avatar answered Sep 28 '22 06:09

andreycha