C#和Zip文件操作

Tac*_*667 2 .net c# zip

这是我正在寻找的:

我需要打开一个zip文件的图像并迭代它的内容.首先,zip容器文件有子目录,在一个"IDX"里面有我需要的图像.我将zip文件内容解压缩到目录没有问题.我的zip文件非常庞大,就像在GB中一样巨大,所以我希望能够打开文件并拉出图像,因为我一次一个地迭代它们来处理它们.

完成后我只关闭zip文件.这些图像实际上存放在数据库中.

有没有人知道如何使用,希望,免费工具或内置api?此过程将在Windows计算机上完成.

谢谢!

har*_*rpo 6

SharpZipLib是满足您要求的绝佳工具.

我用它来处理巨型嵌套zip文件(即ZIP文件中的ZIP文件)内的目录中的巨型文件,使用流.我能够在压缩流的顶部打开一个拉链流,这样我就可以调查内部zip的内容而无需提取整个父级.然后,您可以使用流来查看内容文件,这可以帮助您确定是否要提取它.它是开源的.

编辑:库中的目录处理并不理想.我记得,它包含一些目录的单独条目,而其他目录则隐含在文件条目的路径中.

这是我用于收集特定级别(_startPath)的实际文件和文件夹名称的代码的摘录.如果您对整个包装类感兴趣,请告诉我.

// _zipFile = your ZipFile instance
List<string> _folderNames = new List<string>();
List<string> _fileNames = nwe List<string>();
string _startPath = "";
const string PATH_SEPARATOR = "/";

foreach ( ZipEntry entry in _zipFile )
{
    string name = entry.Name;

    if ( _startPath != "" )
    {
        if ( name.StartsWith( _startPath + PATH_SEPARATOR ) )
            name = name.Substring( _startPath.Length + 1 );
        else
            continue;
    }

    // Ignore items below this folder
    if ( name.IndexOf( PATH_SEPARATOR ) != name.LastIndexOf( PATH_SEPARATOR ) )
        continue;

    string thisPath = null;
    string thisFile = null;

    if ( entry.IsDirectory ) {
        thisPath = name.TrimEnd( PATH_SEPARATOR.ToCharArray() );
    }
    else if ( entry.IsFile )
    {
        if ( name.Contains( PATH_SEPARATOR ) )
            thisPath = name.Substring( 0, name.IndexOf( PATH_SEPARATOR ) );
        else
            thisFile = name;
    }

    if ( !string.IsNullOrEmpty( thisPath ) && !_folderNames.Contains( thisPath ) )
        _folderNames.Add( thisPath );

    if ( !string.IsNullOrEmpty( thisFile ) && !_fileNames.Contains( thisFile ) )
        _fileNames.Add( thisFile );
}
Run Code Online (Sandbox Code Playgroud)