SharpZipLib 壓縮後傳輸給第三方平臺沒法識別問題

問題描述:在項目中須要將文件壓縮而後傳輸給三方進行彩信發送,使用SharpZipLib 進行壓縮,原先使用J#進行壓縮處理,可是用SharpZipLib壓縮後的zip文件傳輸過去以後,總會報發送失敗。最後在加入 s.UseZip64 = UseZip64.Off;這一句話後,解決問題。特此記錄。ui

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();
                }
相關文章
相關標籤/搜索