2016-08-01 119 views
2

我想創建一個存儲文件的zip存檔工作,並設置ZipArchiveEntry.CompressionLevelCompressionLevel.NoCompression, 但是當我在釋放模式運行我的Android APK,所有ZipArchiveEntries壓縮並具有比> 0%。
我使用xamarin for android 4.1.1.3並測試了lenovo tab 4 A7-30GC和asus Z00VD中的apk。
示例代碼:設置ZipArchiveEntry.CompressionLevel到CompressionLevel.NoCompression不xamarin的Android

public void AddToArchive(string EntryName, string Path, DateTime TimeStamp) 
    { 
     ZipArchiveEntry zipEntry = this.Archive.CreateEntry(EntryName, CompressionLevel.NoCompression); 
     zipEntry.LastWriteTime = TimeStamp; 
     using (Stream entryStream = zipEntry.Open()) 
     { 
      using (Stream fileStream = File.Open(Path, FileMode.Open, FileAccess.Read, FileShare.Read)) 
      { 
       fileStream.CopyTo(entryStream); 
       fileStream.Close(); 
      } 
      entryStream.Close(); 
     } 
    } 

謝謝。

回答

0

基於Microsoft .Net參考源(通過Mono源),設置CompressionLevel僅爲下層壓縮代碼提供「提示」。

您將會看到,在「零」壓縮級別進行壓縮時,某些文件最終會看到由於文件優化而產生的某些壓縮,這些壓縮無論請求的壓縮級別如何都可以完成。這是會發現跨Mono,Xamarin.Android,Xamarin.iOS,.Net等...

這是一個抽象的概念,而不是ZLib壓縮級別。 可能有也可能沒有與deflater的可能實現特定級別參數的任何對應關係。

///------------------------------------------------------------------------------ 
/// <copyright file="CompressionLevel.cs" company="Microsoft"> 
///  Copyright (c) Microsoft Corporation. All rights reserved. 
/// </copyright>        
/// 
/// <owner>gpaperin</owner> 
///------------------------------------------------------------------------------ 
// This is an abstract concept and NOT the ZLib compression level. 
// There may or may not be any correspondance with the a possible implementation-specific level-parameter of the deflater. 
public enum CompressionLevel { 
    Optimal = 0, 
    Fastest = 1, 
    NoCompression = 2 
}