c# - 在 azure blob 存储中设置 Ionic Zip 密码,并为 zip 文件夹而不是文件设置最佳压缩

标签 c# azure azure-storage ionic-zip

如何设置 zip 文件夹最佳压缩并为 Zip 文件夹设置密码,我使用的代码很少,请帮助我如何为 zip 文件夹设置最佳压缩和密码。

using (var zipStream = new MemoryStream())                    
{ 
zipFile.Save(zipStream);
zipStream.Seek(0, SeekOrigin.Begin);                        
CloudBlockBlob cblob = container.GetBlockBlobReference("MockTestZip/MT-" + this.mockExamId + ".zip");
cblob.UploadFromStream(zipStream);                        
}

我刚刚在其中添加了这两行,但在 azure blob 存储中的 zip 文件夹中未设置密码

zipFile.CompressionLevel = Ionic.Zlib.CompressionLevel.BestCompression;
zipFile.Password = "encrypt";

最佳答案

根据你的描述,我杠杆DotNetZip version 1.10.1在我这边测试这个问题。这是关于 ZipFile 中的 Password 属性的注释:

When writing a zip archive, this password is applied to the entries, not to the zip archive itself. It applies to any ZipEntry subsequently added to the ZipFile, using one of the AddFile, AddDirectory, AddEntry, or AddItem methods, etc.

根据您的情况,我假设您可以将文件存储在没有密码的 zip 文件中,然后将该 zip 文件存储在带有密码的第二个外部 zip 文件中,如下所示:

using (ZipFile zipFile = new ZipFile())
{
    zipFile.CompressionLevel = Ionic.Zlib.CompressionLevel.BestCompression;
    zipFile.Password = "{your-password}";
    zipFile.AddFile(@"inner.zip",""); //Passing the empty string ("") to store your zip file at the root path within the archive.
    using (var zipStream = new MemoryStream())
    {
        zipFile.Save(zipStream);
        zipStream.Seek(0, SeekOrigin.Begin);
        CloudBlockBlob cblob = container.GetBlockBlobReference("MockTestZip/MT-" + this.mockExamId + ".zip");
        cblob.UploadFromStream(zipStream);
    }
}

关于c# - 在 azure blob 存储中设置 Ionic Zip 密码,并为 zip 文件夹而不是文件设置最佳压缩,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41693641/

相关文章:

c# - FileSystemWatcher 检测 zip 文件

c# - 你如何获取字符串中的第一个字母?

azure - 如何与 Mesos 和 Marathon 安全地共享 Azure 容器服务中的私有(private) docker 存储库登录凭据

azure - 如何在azure上设计微服务系统并使用工作流程按顺序调用它们

php - MySQL 尝试以访问权限禁止的方式访问套接字

azure - Azure Blob 存储容器有文件数量限制吗?

c# - 为什么要序列化整个 HttpResponseMessage?

c# - 如何在 C# GUI 中嵌入 C OpenGL 应用程序?

azure - 可以从 Azure 网站使用新的 Azure 文件服务吗?

azure - 使用 ARM 模板启用 Azure StorageV2 静态网站(预览)功能