0
以下行給出的問題解壓縮郵件附件
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文件,你試圖解壓縮... –
您是否在壓縮時將任何額外的字節添加到實際的字節數組? – Rezoan