-1
In the program I am writing I download a ZIP file over the internet and then need to upload the files extracted from ZIP to another place.
Turns out I can’t find a way to read the contents of that ZIP file - now a Stream - without first creating a Filestream and saving it to disk. I would prefer a thousand times to work everything in memory. Today I do so (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?