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?