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

Unzip the compressed zip under mac #342

Closed
5chn opened this issue May 7, 2019 · 10 comments
Closed

Unzip the compressed zip under mac #342

5chn opened this issue May 7, 2019 · 10 comments
Labels

Comments

@5chn
Copy link

5chn commented May 7, 2019

Hello, author, would you like to ask your SharpZipLib.dll package to extract the zip package compressed by mac? Have you ever encountered a zip package that is compressed under the mac, and the zero-byte file is coming out.

@5chn
Copy link
Author

5chn commented May 7, 2019

I use the zip package made by mac computer, and then use C# SharpZipLib.dll to extract the zip of this mac, get the result of zero byte file, the file should not be zero byte.

@piksel
Copy link
Member

piksel commented May 22, 2019

Hello! Please use the issue template when creating an issue like this.
What version of SharpZipLib are you using? What version of .NET?
Could you provide the code that you used to extract the contents?
How was the file created, using what software on macOS?

@5chn
Copy link
Author

5chn commented May 23, 2019

sharpZipLib version is 0.86.0.518, .NET version is Unity 3.5 .net Subset Base Class Libraries.
extract code:

var zipFile = File.OpenRead(m_currentUnzipItem.SrcZipFile);
m_currentUnzipItem.totalSize = (int)zipFile.Length;
ZipInputStream unzipStream = new ZipInputStream(zipFile);
try
{
    if (m_unzipProcessList.IndexOf(m_currentUnzipItem) < 0)
    {
        m_unzipProcessList.Add(m_currentUnzipItem);
    }
    ZipEntry theEntry;
    while ((theEntry = unzipStream.GetNextEntry()) != null)
    {
        //先创建目录
        string fullName = m_currentUnzipItem.ToDir + theEntry.Name;
        string dir = Path.GetDirectoryName(fullName);

        if (!Directory.Exists(dir))
        {
            Directory.CreateDirectory(dir);
        }
        Debuger.Log("file={0}, dir={1}", theEntry.Name, dir);
        if (theEntry.IsFile)
        {
            if (File.Exists(fullName))
            {//删除原有文件
                //File.Delete(fullName);
            }
            FileStream streamWriter = File.Create(fullName);
            try
            {
                //unzipStream.Seek(theEntry.Offset, SeekOrigin.Begin);
                int readTotalLen = 0;
                while (readTotalLen < theEntry.Size)
                {
                    Array.Clear(UnzipBuffer, 0, UnzipBuffer.Length);
                    int readlen = unzipStream.Read(UnzipBuffer, 0, UnzipBuffer.Length);
                    readTotalLen += readlen;
                    streamWriter.Write(UnzipBuffer, 0, readlen);
                    streamWriter.Flush();
                    m_currentUnzipItem.unzipedSize = (int)zipFile.Position;
                    //Debuger.Log("unzip={0}, total={1}, m_currentUnzipItem.stopUnzip:{2}", m_currentUnzipItem.unzipedSize, m_currentUnzipItem.totalSize, m_currentUnzipItem.stopUnzip);
                    if (m_currentUnzipItem.stopUnzip)
                    {
                        break;
                    }
                }
            }
            catch (Exception ex)
            {
                Debuger.Error("解压出错1:{0},{1}", m_currentUnzipItem.SrcZipFile, ex.ToString());
                m_currentUnzipItem.errorCode = ZipErrorCode.SingleFileError;

            }
            streamWriter.Close();
            streamWriter.Dispose();
        }
        if (m_currentUnzipItem.stopUnzip)
        {
            break;
        }
    }
}
catch(Exception ext)
{
    Debuger.Error("解压出错2:{0},{1}", m_currentUnzipItem.SrcZipFile, ext.ToString());
    m_currentUnzipItem.errorCode = ZipErrorCode.ZipFileError;
}

Compressed files by default zip mode on MAC computer, right-click file name, create compressed files

The problem is unzipStream. GetNextEntry (). size is - 1L;
The file size of the pair should not be - 1L
It's good for me to use the same code to process zip files compressed under Windows.

@5chn 5chn closed this as completed May 23, 2019
@5chn 5chn reopened this May 23, 2019
@Numpsy
Copy link
Contributor

Numpsy commented May 23, 2019

The problem is unzipStream. GetNextEntry (). size is - 1L;

Can that happen if the archive is using Zip64? (I couldn't say offhand if the macOS zip tool produces those)

@piksel
Copy link
Member

piksel commented May 23, 2019

Yeah, this seems related to Zip64. Are you able to try the latest package? I'm not too familiar with using packages in unity, but I think the lastest version should support .NET standard.

@5chn
Copy link
Author

5chn commented May 24, 2019

The latest version does not have DLL packages

@5chn
Copy link
Author

5chn commented May 24, 2019

Can you give me a latest version of the DLL package? I can't install the nupkg file. Thank you.

@Numpsy
Copy link
Contributor

Numpsy commented May 24, 2019

The nupkg is just a zip file, you should be able to just extract it and copy the dlls out of it.

@piksel
Copy link
Member

piksel commented Jun 18, 2019

Probably caused by #357

@piksel
Copy link
Member

piksel commented Nov 10, 2020

Closing this as it should have been fixed in latest release.

@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
Projects
None yet
Development

No branches or pull requests

3 participants