【发布时间】:2013-07-08 07:31:28
【问题描述】:
下面这行给出了问题
content = new StreamReader(new GZipStream(new MemoryStream(a.RawBytes), CompressionMode.Decompress)).ReadToEnd();
InvalidDataException 发生:GZip 标头中的幻数不是 正确的。确保您在 GZip 流中。
我不能将附件转换为字节数组还是我做错了什么?
Attachment a = (from x in mail.Attachments.OfType<Attachment>()
where !string.IsNullOrEmpty(x.Body) || x.RawBytes != null
select x).FirstOrDefault();
AttachmentName = a.Name;
string AttachmentType = a.Name.Substring(a.Name.Length - 3, 3).ToUpper();
switch (AttachmentType)
{
case "ZIP":
content = new StreamReader(new GZipStream(new MemoryStream(a.RawBytes), CompressionMode.Decompress)).ReadToEnd();
break;
default:
content = new StreamReader(new MemoryStream(a.RawBytes)).ReadToEnd();
break;
}
【问题讨论】:
-
Gzip 标头包含一个幻数(文件格式签名),这似乎不是 Gzip 文件,您尝试解压缩...
-
压缩时是否在实际字节数组中添加了额外的字节?
标签: c# gzipstream