Cannot create DotNetZip ZipFile from file download via HTTP Response

Oct 16, 2013 at 10:20 PM
Edited Oct 16, 2013 at 10:29 PM
I posted this on stackoverflow but couldnt get a resolution.

I am try to download a zip file via a url to extract files from. I would rather not have to save it a temp file (which works fine) and rather keep it in memory - it is not very big. For example, if I try to download this file:

using this code:
using Ionic.Zip;
HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create(URL);
HttpWebResponse response = (HttpWebResponse)request.GetResponse();

if (response.ContentLength > 0)
    using (MemoryStream zipms = new MemoryStream())
        int bytesRead;
        byte[] buffer = new byte[32768];

        using (Stream stream = response.GetResponseStream())
            while ((bytesRead = stream.Read(buffer, 0, buffer.Length)) > 0)
                zipms.Write(buffer, 0, bytesRead);

            ZipFile zip = ZipFile.Read(stream); // <--ERROR: "This stream does not support seek operations. "

        using (ZipFile zip = ZipFile.Read(zipms)) // <--ERROR: "Could not read block - no data!  (position 0x00000000) "
        using (MemoryStream txtms = new MemoryStream())
            ZipEntry csentry= zip["Download File Test.cs"];
            txtms.Position = 0;
            using (StreamReader reader = new StreamReader(txtms))
                string csentry = reader.ReadToEnd();
Note where i flagged the errors I am receiving. With the first one, it does not like the System.Net.ConnectStream. If I comment that line out and allow it to hit the line where I note the second error, it does not like the MemoryStream. I did see this posting: but I am having the same issues that others mention about not having more then 4 overloads of the Read method so I cannot try the WebClient.

However, if I do everything via a FileStream and save it to a temp location first, then point ZipFile.Read at that temp location, everything works including extracting any contained files into a MemoryStream.

Thanks for any help.