Skip to content

Compression Method Stored leads to corrupt archive #492

Closed

Description

@martinweihrauch

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

Activity

  1. Numpsy commented on Aug 3, 2020

    @Numpsy
    Contributor

    (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.

  2. piksel commented on Aug 4, 2020

    @piksel
    Member

    Yeah, hopefully 1.3 will be out pretty soon!

  3. added
    fixed in next
    on Aug 4, 2020
  4. piksel commented on Nov 10, 2020

    @piksel
    Member

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    fixed in next

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions