jaime-olivares / zipstorer

A Pure C# Class to Store Files in Zip
MIT License
183 stars 63 forks source link

Not Working Support for Zip64 (file sizes > 4GB) #39

Closed mahendra-25 closed 3 months ago

mahendra-25 commented 4 years ago

Your helper file is very much useful, I have used in my 3-5 projects but when I used in recent project where zipping was of more than 6gb folder, zip file was generating successfully but unzipping was making issue in checksum error.

After going through your code and comments I found that support for larger sizes file you have changed the WriteEndRecord parameter size but not changed in close function to send the value for the same so I have changed some little two things in two lines of your code.

Please change the data type in ### close() function at line### 334, 335 from uint to long as when there is bigger sizes files the stream position is at greater than the uint max size.

Please look the same and do changes for making this more awesome successful code.

    /// <summary>
    /// Updates central directory (if pertinent) and close the Zip storage
    /// </summary>
    /// <remarks>This is a required step, unless automatic dispose is used</remarks>
    public void Close()
    {
        if (this.Access != FileAccess.Read)
         {
            long centralOffset = this.ZipFileStream.Position;
            long centralSize = 0;

            if (this.CentralDirImage != null)
                this.ZipFileStream.Write(CentralDirImage, 0, CentralDirImage.Length);

            for (int i = 0; i < Files.Count; i++)
            {
                long pos = this.ZipFileStream.Position;
                this.WriteCentralDirRecord(Files[i]);
                centralSize += (uint)(this.ZipFileStream.Position - pos);
            }

            if (this.CentralDirImage != null)
                this.WriteEndRecord(centralSize + (uint)CentralDirImage.Length, centralOffset);
            else
                this.WriteEndRecord(centralSize, centralOffset);
        }

        if (this.ZipFileStream != null && !this.leaveOpen)
        {
            this.ZipFileStream.Flush();
            this.ZipFileStream.Dispose();
            this.ZipFileStream = null;
        }
    }

After changing code then to file extraction giving error of checksum please look in this issue.

jaime-olivares commented 3 years ago

Hi, I appreciate the analysis. Can you please create a pull request?