I have a zipped file having size of several GBs, I want to get the size of Unzipped contents but don't want to actually unzip the file in C#, What might be the Library I can use? When I right click on the .gz file and go to Properties then under the Archive
Tab there is a property name TotalLength
which is showing this value. But I want to get it Programmatically using C#.. Any idea?
You can use the pretty-print and white-space only options to estimate the compression of non-minified content. If you need an estimate: Start with 100 JS files that have gone through the same minification pipeline. For each file, compute the ratio in sizes between gzip -c "$f" | wc -c and wc -c "$f"
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.
GZIP produces zipped files with the . gz extension. Although it's not commonly used on Windows, this compression format is still popular on UNIX/LINUX. If you receive a GZIP file, you can save it to your desktop and open it with WinZip.
If you need to check the contents of a compressed text file on Linux, you don't have to uncompress it first. Instead, you can use a zcat or bzcat command to extract and display file contents while leaving the file intact. The "cat" in each command name tells you that the command's purpose is to display content.
The general syntax for the gzip command is as follows: gzip [OPTION]... [FILE]... Gzip compresses only single files and creates a compressed file for each given file.
When used with the -l option, gzip shows statistics about the given compressed files: The output will include the uncompressed file name, the compressed and uncompressed size, and the compression ratio: To get more information, add the -v option:
Gzip compresses only single files and creates a compressed file for each given file. By convention, the name of a file compressed with Gzip should end with either .gz or .z. If you want to compress multiple files or directory into one file, first you need to create a Tar archive and then compress the .tar file with Gzip.
By default, gzipkeeps the original file name and timestamp in the compressed file. These are used when decompressing the file with the -Noption. This is useful when the compressed file name was truncated or when the time stamp was not preserved after a file transfer.
The last 4 bytes of the gz file contains the length.
So it should be something like:
using(var fs = File.OpenRead(path))
{
fs.Position = fs.Length - 4;
var b = new byte[4];
fs.Read(b, 0, 4);
uint length = BitConverter.ToUInt32(b, 0);
Console.WriteLine(length);
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With