首页 > 代码库 > SharpZipLib 压缩后传输给第三方平台无法识别问题

SharpZipLib 压缩后传输给第三方平台无法识别问题

问题描述:在项目中需要将文件压缩然后传输给三方进行彩信发送,使用SharpZipLib 进行压缩,原先使用J#进行压缩处理,但是用SharpZipLib压缩后的zip文件传输过去之后,总会报发送失败。最后在加入 s.UseZip64 = UseZip64.Off;这一句话后,解决问题。特此记录。

using (ZipOutputStream s = new ZipOutputStream(File.Create(argZipPath)))                {                    s.UseZip64 = UseZip64.Off;                    s.SetLevel(9); // 0 - store only to 9 - means best compression                    byte[] buffer = new byte[4096];                    foreach (string file in argFiles)                    {                        // Using GetFileName makes the result compatible with XP                        // as the resulting path is not absolute.                        ZipEntry entry = new ZipEntry(Path.GetFileName(file));                        // Setup the entry data as required.                        // Crc and size are handled by the library for seakable streams                        // so no need to do them here.                        // Could also use the last write time or similar for the file.                        entry.DateTime = DateTime.Now;                        s.PutNextEntry(entry);                        using (FileStream fs = File.OpenRead(file))                        {                            int sourceBytes;                            do                            {                                sourceBytes = fs.Read(buffer, 0, buffer.Length);                                s.Write(buffer, 0, sourceBytes);                            } while (sourceBytes > 0);                        }                    }                    s.Finish();                    s.Close();                }

  

SharpZipLib 压缩后传输给第三方平台无法识别问题