将ZipArchiveEntry.CompressionLevel设置为CompressionLevel.NoCompr

本文关键字:CompressionLevel NoCompr 设置 ZipArchiveEntry | 更新日期: 2023-09-27 17:59:27

我想为存储文件创建一个zip存档,并将ZipArchiveEntry.CompressionLevel设置为CompressionLevel.NoCompression,但当我在发布模式下运行我的android apk时,所有ZipArchiveEntries都被压缩,并且比率>0%
我使用xamarin用于android 4.1.1.3,并在联想选项卡4 A7-30GC和华硕Z00VD中测试apk
示例代码:

 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();
        }
    }

谢谢。

将ZipArchiveEntry.CompressionLevel设置为CompressionLevel.NoCompr

基于Microsoft.Net参考源(通过Mono源),设置CompressionLevel仅为底层压缩代码提供"提示"。

您将看到,当以"零"压缩级别压缩某些文件时,由于无论请求的压缩级别如何都会进行文件优化,因此最终会看到一些压缩。这将在Mono、Xamarin.Android、Xamari.OS、.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
}
相关文章:
  • 没有找到相关文章