I need to save a compressed byte stream in to a database table, the problem is that whenever i open the file, winZip/winRar/windows reports that the archive is corrupt. I've tried setting leavOpen on the ZipArchive (as suggested in some other posts) but it make no difference.
any ideas?
private byte[] Compress(byte[] pData, string pFileName)
{
CompressionSettings lSettings = new LzmaSettings();
using (MemoryStream lMemoryStream = new MemoryStream()) {
using (ZipArchive lArchive = new ZipArchive(lMemoryStream, ZipArchiveMode.Create, false, null)) {
ZipArchiveEntry lAttachment = lArchive.CreateEntry(pFileName, lSettings);
using (var lAttachmentStream = lAttachment.Open()) {
using (var lStreamWriter = new StreamWriter(lAttachmentStream)) {
lStreamWriter.Write(pData);
}
}
}
return lMemoryStream.ToArray();
}
}