Read ZIP file contents without writing to disk

-1

In the program I'm writing, I download a ZIP file over the internet and then need to upload the extracted ZIP files to another place.

It turns out that I can not find a way to read the contents of this ZIP file - now a Stream - without first creating a FileStream and writing it to disk. I would prefer a thousand times to work everything in memory. Today I do this (with System.IO ):

string zipLocation = Directory.GetCurrentDirectory() + "\teste.zip";

//faz o download e grava no disco
using (GetObjectResponse response = await S3Client.GetObjectAsync(req))
using (Stream responseStream = response.ResponseStream)
using (FileStream fileStream = File.Create(zipLocation))
{
    responseStream.CopyTo(fileStream);
    fileStream.Seek(0, SeekOrigin.Begin);

    using (var zip = new ZipArchive(file, ZipArchiveMode.Read))
    {
        //loop pelos arquivos dentro do ZIP
        foreach (ZipArchiveEntry entry in zip.Entries)
        {
            //faz o upload
        }
    }
}

As you can see, I had to write the file to disk using File.Create (). How to do without this part?

    
asked by anonymous 02.01.2019 / 22:29

2 answers

4

You've already seen the DotNetZip .

using (ZipFile zip = ZipFile.Read("omeuzip"))
{
  ZipEntry FicheiroZip = zip["documento.txt"];
  FicheiroZip.Extract(OutputStream);
}
    
03.01.2019 / 00:13
0

Look, I apologize for asking that question. Working a bit more in my code I was able to use MemoryStream, yes. I thought it was not possible before. I tried to delete the question and it did not work.

...
using (GetObjectResponse response = await S3Client.GetObjectAsync(req))
using (Stream responseStream = response.ResponseStream)
using (MemoryStream memoryStream = new MemoryStream()) //funciona perfeitamente
    
03.01.2019 / 14:44