解压时候报 GZip 头中的幻数不正确。请确保正在传入 GZip 流

CloudOfFly CloudOfFly 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区

public static Stream CompressStream(Stream stream)
{
if (stream == null)
{
throw new ArgumentNullException("stream");
}
//压缩流
GZipStream gzipStream = new GZipStream(stream, CompressionMode.Compress,true);
//将缓冲区中的数据刷新到基础流
gzipStream.Flush();
//返回压缩流对象
return gzipStream;

}

/// <summary>
/// 解压流操作
/// </summary>
/// <param name="stream">需要解压的流对象</param>
/// <returns>返回解压GZipStream流对象</returns>
public static Stream DecompressStream(Stream stream)
{
if (stream == null)
{
throw new ArgumentNullException("stream");
}

GZipStream gzipStream = new GZipStream(stream, CompressionMode.Decompress);
gzipStream.Flush();
return gzipStream;
}


//创建一个编码对象
UTF8Encoding uniEncoding = new UTF8Encoding();
//将字符串编码成字节序列
byte[] firstString = uniEncoding.GetBytes("Invalid file path characters are: ");
MemoryStream memoryStream = new MemoryStream();

// 将字节数组写入到当前流中.
memoryStream.Write(firstString, 0, firstString.Length);

用上面生成一个流 对其加密 加密后解密 就报 GZip 头中的幻数不正确。请确保正在传入 GZip 流
错误
...全文
评论 11
收藏 已收藏
分享
返回顶部
CloudOfFly
C# 111,129 成员 642,540 内容