haf / DotNetZip.Semverd

Please use System.IO.Compression! A fork of the DotNetZip project without signing with a solution that compiles cleanly. This project aims to follow semver to avoid versioning conflicts. DotNetZip is a FAST, FREE class library and toolset for manipulating zip files. Use VB, C# or any .NET language to easily create, extract, or update zip files.
Other
545 stars 218 forks source link

Exception extracting from ZipEntry #197

Open lxman opened 4 years ago

lxman commented 4 years ago
    private static MemoryStream GetClientFile(string file)
    {
        MemoryStream ms = new MemoryStream();
        using (ZipInputStream zip = new ZipInputStream(file))
        {
            ZipEntry ze = zip.GetNextEntry();
            while (!(ze is null))
            {
                if (ze.FileName.EndsWith("tag to locate entry"))
                {
                    ze.ExtractWithPassword(ms, "password");
                    return ms;
                }

                ze = zip.GetNextEntry();
            }
        }
        return ms;
    }

When I run this I get:

System.InvalidOperationException: Use Extract() only with ZipFile.

I get no intellisense errors, and per the docs, I think I should be able to do this.

darkms commented 4 years ago

Hi, have you tried using ZipFile.Read(file) instead of ZipInputStream? Here's an example: https://github.com/haf/DotNetZip.Semverd/blob/f7e1c3547540bf43bc6819dac489e6b107b1c07a/src/Help/Code%20Examples/Csharp.htm#L279