简体   繁体   English

C#-压缩gzip中的文件和文件夹

[英]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). 我需要创建一个压缩文件(rar,gz或其他巫婆支持大文件和大压缩文件)。 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. 我需要在压缩文件中复制结构zip压缩显然有一些限制,例如文件大小和压缩文件大小。 I have tried with GZipStream, but i not discovered how to create folders inside gz file. 我已经尝试过使用GZipStream,但是我没有发现如何在gz文件中创建文件夹。

GZIP can only compress streams (hence the name GZip Stream ). GZIP只能压缩流(因此名为GZip Stream )。 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. 这就是为什么gzip通常与tar(例如.tar.gz文件)一起使用的原因,其中tar从文件夹结构中创建档案,然后gzip压缩该档案。

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 . 如果您不能出于目的使用ZipArchive或ZipFile(位于System.IO.Compression.FileSystem ),则最好的选择是使用外部库/程序包,例如SharpZipLibSharpCompress

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM