c# - GZipStream 抛出异常:无法正确加载底层压缩例程
问题描述
我正在使用以下方法压缩文件,但它会引发异常“无法正确加载底层压缩例程”。
CompressFile(string sDir, string sRelativePath, GZipStream zipStream)
{
//Compress file name
char[] chars = sRelativePath.ToCharArray();
zipStream.Write(BitConverter.GetBytes(chars.Length), 0, sizeof(int));
foreach (char c in chars)
zipStream.Write(BitConverter.GetBytes(c), 0, sizeof(char));
//Compress file content
byte[] bytes = File.ReadAllBytes(System.IO.Path.Combine(sDir, sRelativePath));
zipStream.Write(BitConverter.GetBytes(bytes.Length), 0, sizeof(int));
zipStream.Write(bytes, 0, bytes.Length);
}
解决方案
推荐阅读
- javascript - Javascript:将 JSON 解析为字符串数组
- python - 请求不发送具有正确 ip 的请求
- java - 如何创建安全的 Lombok JPA 实体?
- .net - 如何在毛伊岛使用 NavigationPage?
- c++ - 我可以在没有默认初始化的情况下初始化数组的 std::unique_ptr 吗(我只想让它有虚拟值)
- r - 通过增加样品编号分配组 ID
- javascript - 如何在另一个嵌套屏幕中显示嵌套屏幕?
- snowflake-cloud-data-platform - 如何将 Snowsql 配置为在连接 Snowflake 后立即自动运行 sql 脚本?
- javascript - 如何在浏览器重新加载时发出数据?
- phpstorm - Xdebug 3 不适用于 PhpStorm 和 WSL2 (Ubuntu 20.04)