gpt4 book ai didi

c# - 将 ZipArchiveEntry.CompressionLevel 设置为 CompressionLevel.NoCompression 在 xamarin android 中不起作用

转载 作者:太空宇宙 更新时间:2023-11-03 15:17:03 25 4
gpt4 key购买 nike

我想为存储文件创建一个 zip 存档并将 ZipArchiveEntry.CompressionLevel 设置为 CompressionLevel.NoCompression,但是当我在 Release模式下运行我的 android apk 时,所有 ZipArchiveEntries 都被压缩并且比率 >0%。
我使用 xamarin for android 4.1.1.3 并在 lenovo tab 4 A7-30GC 和 asus 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();
}
}

谢谢。

最佳答案

基于 Microsoft .Net 引用源(通过 Mono 源),设置 CompressionLevel 仅为底层压缩代码提供“提示”。

您会看到某些文件在以“零”压缩级别压缩时最终会看到一些压缩,这是由于无论请求的压缩级别如何都进行了文件优化。这将在 Mono、Xamarin.Android、Xamarin.iOS、.Net 等中找到...

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.

///------------------------------------------------------------------------------
/// <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
}

关于c# - 将 ZipArchiveEntry.CompressionLevel 设置为 CompressionLevel.NoCompression 在 xamarin android 中不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38704792/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com