Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Compression Method Stored leads to corrupt archive #492

Closed
martinweihrauch opened this issue Aug 3, 2020 · 3 comments
Closed

Compression Method Stored leads to corrupt archive #492

martinweihrauch opened this issue Aug 3, 2020 · 3 comments
Labels
fixed in next Bug not present main branch, but it has not been released yet

Comments

@martinweihrauch
Copy link

martinweihrauch commented Aug 3, 2020

Steps to reproduce

With the current library from Nuget (1.2), I get a corrupt archive, if I use this code:
If I dont have CompressionMethod.Stored, then the archive works, but the uncompressed files are always few bytes bigger than the original files. I need the files to be exactly the same (original size = size of file in ZIP archive).

I have fixed this whole thing for myself before (see my older issue), but in 1.2, this still seems to be flawed.

Best

Martin


public ZipWriter(string filename)
        {
            _sziFilename = filename;
            FileStream fsOut = File.Create(_sziFilename);
            _zipStream = new ZipOutputStream(fsOut);

            _zipStream.SetLevel(0); //0-9, 9 being the highest level of compression

        }

        public void AddFileToZip(string filenameInZip, MemoryStream memTile)
        {
            memTile.Position = 0;
            DateTime creationTimeUtc = DateTime.Now;
            string entryName = filenameInZip;
            entryName = ZipEntry.CleanName(entryName); // Removes drive from name and fixes slash direction
            var newEntry = new ZipEntry(entryName)
            {
                DateTime = creationTimeUtc,
                CompressionMethod = CompressionMethod.Stored,
                Size = memTile.Length,
            };
            _zipStream.PutNextEntry(newEntry);

            // Zip the file in buffered chunks
            // the "using" will close the stream even if an exception occurs
            byte[] buffer = new byte[4096];
            StreamUtils.Copy(memTile, _zipStream, buffer);
            _zipStream.CloseEntry();

Expected behavior

ZIP archive should be OK

Actual behavior

ZIP archive corrupt

Version of SharpZipLib

1.2.0

Obtained from (only keep the relevant lines)

  • Package installed using NuGet
@Numpsy
Copy link
Contributor

Numpsy commented Aug 3, 2020

(see my older issue)

you mean #398?

The issue was hopefully fixed in #406, but that hasn't found its way in to an official release yet.

@piksel
Copy link
Member

piksel commented Aug 4, 2020

Yeah, hopefully 1.3 will be out pretty soon!

@piksel piksel added the fixed in next Bug not present main branch, but it has not been released yet label Aug 4, 2020
@piksel
Copy link
Member

piksel commented Nov 10, 2020

I am closing this as it should be fixed in the current release. If not, please make a new issue.

@piksel piksel closed this as completed Nov 10, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
fixed in next Bug not present main branch, but it has not been released yet
Projects
None yet
Development

No branches or pull requests

3 participants