SharpZipLib ~ Как извлечь определенные файлы из zip

Ok,

У меня есть список файлов (объекты SourceFile, которые содержат только имя файла), затем я хочу вытащить эти конкретные файлы из zip и сбросить их во временный каталог, чтобы я мог распространять их позже.

Я придумал это, но я не уверен, как действовать дальше.

private List<string> ExtractSelectedFiles()
{
List<SourceFile> zipFilePaths = new List<SourceFile>();
List<string> tempFilePaths = new List<string>();

if (!File.Exists(this.txtSourceSVNBuildPackage.Text)) { return tempFilePaths; };

FileStream zipFileStream = File.OpenRead(this.txtSourceSVNBuildPackage.Text);
ZipInputStream inStream = new ZipInputStream(zipFileStream);

foreach (SourceFile currentFile in _selectedSourceFiles)
{
    bool getNextEntry = true;

    while (getNextEntry)
    {
            ZipEntry entry = inStream.GetNextEntry();

        getNextEntry = (entry != null);

                if (getNextEntry)
            {
             if (fileType == ".dll")
             {
                if (sourcefile.Name == Path.GetFileName(entry.Name))
                {
                //Extract file into a temp directory somewhere

                //tempFilePaths.Add("extractedfilepath")
                }
             }
            }
          }
      }

    return tempFilePaths;
}

К вашему сведению:

public class SourceFile
{
    public string Name { get; set; }  //ex. name = "Fred.dll"
}

person KevinDeus    schedule 02.07.2009    source источник


Ответы (1)


хорошо .. решил, что сообщу вам все после того, как соберу недостающую часть, которая мне нужна.

//in the code somewhere above:
string tempDirectory = Environment.GetEnvironmentVariable("TEMP");
string createPath = tempDirectory + "\\" + Path.GetFileName(entry.Name);


//my missing piece..
//Extract file into a temp directory somewhere
FileStream streamWriter = File.Create(createPath);

int size = 2048;
byte[] data = new byte[2048];
while (true)
{
    size = inStream.Read(data, 0, data.Length);
    if (size > 0)
    {
        streamWriter.Write(data, 0, size);
    }
    else
    {
        break;
    }
}

streamWriter.Close();
person KevinDeus    schedule 02.07.2009