System.IO.Compression.ZipFile .NET 4.5 output zip in not suitable for Linux/Mac/Java

后端 未结 3 1444
清酒与你
清酒与你 2021-02-07 04:07

While using .NET System.IO.Compression.ZipFile.CreateFromDirectory class the outcome zip is badly extracted on system with forward-slash directory separator.

3条回答
  •  爱一瞬间的悲伤
    2021-02-07 04:52

    To overcome this problem a workaround exists:

        class MyEncoder : UTF8Encoding
        {
            public MyEncoder()
            {
    
            }
            public override byte[] GetBytes(string s)
            {
                s = s.Replace("\\", "/");
                return base.GetBytes(s);
           }
        }
        System.IO.Compression.ZipFile.CreateFromDirectory("C:/ABC", "C:/tmp/ABC.zip", CompressionLevel.Fastest, false, new MyEncoder());
    

提交回复
热议问题