Search code examples
c#filecompressiongziprar

C# - Compress files and folders in gzip


i need to create a compressed file (rar, gz, or other witch supports large files and large compressed file). I need to create folders and add files separated by folders. Example: I have a folders structure like this

Folder 1
  Folder 1.1
  Folder 1.2
  Folder 1.3
Folder 2
  Folder 2.1
    Folder 2.1.1

in each folder i have some files. I need to replicate the structure in a compressed file The zip compress aparently has some limitations, as file size and compressed file size. I have tried with GZipStream, but i not discovered how to create folders inside gz file.


Solution

  • GZIP can only compress streams (hence the name GZipStream). That's why gzip is often used together with tar (like .tar.gz files), where tar creates an archive out of the folder structure and gzip compresses that archive.

    If you can't use either ZipArchive or ZipFile (in System.IO.Compression.FileSystem) for your purposes, your best bet would be an external library/package, like SharpZipLib or SharpCompress.