c# - 如何在 C# 中验证多部分压缩(即 zip)文件是否包含所有部分?
问题描述
我想验证像 Zip 这样的多部分压缩文件,因为当压缩文件的任何部分丢失时,它会引发错误,但我想在提取之前对其进行验证,并且不同的软件会创建不同的命名结构。
我还参考了一个DotNetZip相关问题。
下面的截图来自 7z 软件。
第二个屏幕截图来自 C# 的 DotNetZip。
另一件事是,我还想测试它是否也已损坏或不像 7z 软件。请参阅下面的屏幕截图了解我的要求。
请帮我解决这些问题。
解决方案
我不确定您是否能够看到快照中显示的确切错误。但我有一个代码可以帮助您确定多部分文件是否可读。
我用过 nuget Package CombinationStream。
ZipArchive构造函数抛出ArgumentException
或InvalidDataException
如果流不可读。
下面是代码:
public static bool IsZipValid()
{
try
{
string basePath = @"C:\multi-part-zip\";
List<string> files = new List<string> {
basePath + "somefile.zip.001",
basePath + "somefile.zip.002",
basePath + "somefile.zip.003",
basePath + "somefile.zip.004",
basePath + "somefile.zip.005",
basePath + "somefile.zip.006",
basePath + "somefile.zip.007",
basePath + "somefile.zip.008"
};
using (var zipFile = new ZipArchive(new CombinationStream(files.Select(x => new FileStream(x, FileMode.Open) as Stream).ToList()), ZipArchiveMode.Read))
{
// Do whatever you want
}
}
catch(InvalidDataException ex)
{
return false;
}
return true;
}
我不确定这是否是您要查找的内容,或者您需要错误中的更多详细信息。但是希望这可以帮助您解决问题。
推荐阅读
- database - 无法使用自定义配置文件运行 redis,我将 dump.rdb 文件更改为 resrore.rdb,这是另一台机器的备份
- angular - 如何在动态设置 data-automation-id 时修剪空格
- apache-kafka - 在 Kafka KStream 中查找第一个事件
- javascript - 如何在反应js中将json数据插入手风琴中
- android - 为什么 Facebook SDK 给出错误无效哈希键?
- google-bigquery - 通过 DataFlow 到 BigQuery(更新插入)的云存储
- python - 提取由哈希和逗号分隔的文本元素并将其存储在单独的变量中
- java - Shortest way of sorting and comparing two lists
- kubernetes - CrashLoopBackOff - 后退重启失败的容器
- android - android -constraintLayout 如何将高度添加到粘性工具栏?